-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
feat(core): tighten the typings on Provider.provide #15340
Conversation
dadcaef
to
ea13d7d
Compare
*/ | ||
provide: any; | ||
provide: string|Type<any>|InjectionToken<any>|Function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some digging I figured out that Type<any>
doesn't match abstract classes (this is why I added Function
as well. Didn't find anything better)
export interface Type<T> extends Function { new (...args: any[]): T; }
Abstract class can't be instantiated using new
.
So get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T): T
signature doesn't support abstract classes. is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide an example of how Type<any>
does not match? Preferably on http://www.typescriptlang.org/play/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide an example of how Type does not match?
http://prntscr.com/en7kff
Plus CI failed on abstract classes like PlatformRef
when i used
provide: string|Type<any>|InjectionToken<any>;
instead of
provide: string|Type<any>|InjectionToken<any>|Function;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get it now. MyAbstractClass
is not matched by Type<any>
because it does not have new ()
.
interface Type<T> {
new(...args:any[]):T // This is what is missing from abstract classes
}
I wonder if we can expand Type
somehow to include abstract classes as well? Why is Type
not just extends Function
? (@tbosch do you know?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what is missing from abstract classes
yeap, we can't create an abstract class using new.
I wonder if we can expand Type somehow to include abstract classes as well?
I didn't find anything. Here's the same question on StackOverFlow http://stackoverflow.com/questions/36886082/abstract-constructor-type-in-typescript
Looks like we need to remove new(...args:any[]):T
and just extend Function
850435d
to
874d0b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has to be split to the old API which still needs to be supported, and new api going forward.
The new API only allows Type
and InjectableTokens
. Old API supported any
(not just string
) So this has to be broken in a way so that if you using string
than you gate a @deprecated
warning where as when you use InjectableToken
or Type
you do not.
*/ | ||
provide: any; | ||
provide: string|Type<any>|InjectionToken<any>|Function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide an example of how Type<any>
does not match? Preferably on http://www.typescriptlang.org/play/
*/ | ||
provide: any; | ||
provide: string|Type<any>|InjectionToken<any>|Function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closing as outdated |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Closes #15339