TypeScript ambient type information#44
TypeScript ambient type information#44mike-north wants to merge 2 commits intoember-fastboot:mainfrom
Conversation
rwjblue
left a comment
There was a problem hiding this comment.
Seems better to me to use headData: inject.service() instead of relying on the injection into all routes (the same is true of things like ember-data’s store service).
In this particular case, I’m unsure how we can deprecate the auto-injection 🤔. Perhaps by adding a getter with deprecation to Ember.Route.prototype...
|
@rwjblue I think we need to separate what we know to be general best practices
from the task of creating type definitions that accurately reflect what the code is doing. In this case, I got a bit turned around (there is no auto-injection), but for cases like these https://github.com/emberjs/data/blob/0675ef352278a9a489337d2cf46700a768fe8e42/addon/setup-container.js#L72-L74 we should reflect injection onto prototype correctly in type information. I'll update this PR to accurately reflect that explicit injection of the It's still useful to have this small amount of remaining type information, because of the way |
|
Is there any intension in moving TypeScript types here further? |
Because this is an 'extension of ember' kind of addon (often used without being explicitly imported), consumers will need to do one of two things in order to take advantage of this type information.
A. Indicate that this type information is to be included
tsconfig.json
{ "compilerOptions": { "types": [ "ember-cli-head" ] } }B. Import the entry point for this addon from somewhere in their project
app/app.ts
After doing either (A) or (B), type-checking will be happy with developers using the
headDataservice implicitly injected onto all routes, without any further ceremony required.