Skip to content

Commit

Permalink
[BUGFIX stable] Fix model arg to a Route serialize
Browse files Browse the repository at this point in the history
Previously, the internal type here always explicitly added `| undefined`
to the type of the `model` param. This was likely reasonable when the
conversion first happened, since the type here was simply a minimal
`IModel | undefined`. Since the param is now driven by the type param
for the `Route`, though, and defaults to `unknown`, we can just use the
`Model` type param directly, and the implementation handles it correctly
since the was actually already, albeit invisibly, just `unknown`, since
`unknown | undefined` === `unknown`.
  • Loading branch information
chriskrycho committed Jun 29, 2023
1 parent 8123d56 commit 3b83530
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@ember/routing/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
@since 1.0.0
@public
*/
serialize(model: Model | undefined, params: string[]): { [key: string]: unknown } | undefined {
serialize(model: Model, params: string[]): { [key: string]: unknown } | undefined {
if (params.length < 1 || !model) {
return;
}
Expand Down
21 changes: 21 additions & 0 deletions type-tests/@ember/routing-test/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ class ModelTest extends Route {
}
}

class Model {
baseClass = true;
}

class Child extends Model {
baseClass = false;
extraStuff = true;
}

class FooRoute<T extends Model> extends Route<T> {
serialize(object: T): any {
return null;
}
}

class FooChildRoute extends FooRoute<Child> {
serialize(object: Child) {
return object.extraStuff;
}
}

class QPsTest extends Route {
queryParams = {
memberQp: { refreshModel: true },
Expand Down

0 comments on commit 3b83530

Please sign in to comment.