Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX stable] Fix types for Resolver contract #20489

Merged
merged 1 commit into from
Jun 29, 2023
Merged

Conversation

chriskrycho
Copy link
Contributor

@chriskrycho chriskrycho commented Jun 29, 2023

We need Resolver implementors (e.g. ember-resolver) to be able to provide a class which can satisfy this contract, which means we need to support either a static .create() method or a constructor (with a strong preference for the constructor). This is likely to be a common issue with this kind of assignability of classic classes, because it ultimately comes down to the definition of Factory and CoreObject.

To resolve this, add two overloads for CoreObject.prototype.create:

  • One which just produces an instance type with no args at all.
  • One which produces an instance type by merging with passed-in args.

These two overloads also improve the type safety of .create() more generally, allowing us to handle a couple cases which the types did not previously account for (and indeed had given up handling).

This also adds a smoke test for something shaped like the app.ts file generated for every Ember app, so that we can be sure that the code we emit when generating an app actually works. For now, this simply copies over the types from ember-resolver, ember-load-initializers, and a basic environment.

Fixes #20486.

We need `Resolver` implementors (e.g. `ember-resolver`) to be able to
provide a class which can satisfy this contract, which means we need to
support either a static `.create()` method or a constructor (with a
strong preference for the constructor). This is likely to be a common
issue with this kind of assignability of classic classes, because it
ultimately comes down to the definition of `Factory` and `CoreObject`.

To resolve this, add two overloads for `CoreObject.prototype.create`:

- One which just produces an instance type with no args at all.
- One which produces an instance type by merging with passed-in args.

These two overloads also improve the type safety of `.create()` more
generally, allowing us to handle a couple cases which the types did not
previously account for (and indeed had given up handling).

This also adds a smoke test for something shaped like the `app.ts` file
generated for every Ember app, so that we can be sure that the code we
emit when generating an app actually works. For now, this simply copies
over the types from `ember-resolver`, `ember-load-initializers`, and a
basic `environment`.
@chriskrycho chriskrycho merged commit f9af1fe into main Jun 29, 2023
@chriskrycho chriskrycho deleted the types/resolver-fix branch June 29, 2023 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug TypeScript Work on Ember’s types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Resolver in app.ts no longer compiles with the stable types
2 participants