-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
TypeScript 2.4 weak types produces surprising Angular1 error #16536
Comments
export class Demo implements IController {
data: string;
}; there is some relevant discussion about this in #16047 (comment) Adding an index signature on the error message happens to be on the last constituent of the union type, here |
Do you recommend we add an index signature to the d.ts files on DefinitelyTyped? It's a bit weird because it's a lie, but I'm not sure how else to work around this. Perhaps we could require users include the |
|
Right, but that would a user-comprehensible place for us to recommend a fix. When they try adding Otherwise, I'm not sure what the workaround should be -- maybe some |
makes sense
in this case, assuming i am understating the API correctly, the interface is meant to be weak. so not all users are expected to implement
that would make the error go away too, but you do not want to do that every component. |
I see. So is "add an index signature" the general pattern for forcing an interface back to being weak? We might need to sprinkle these around in various other places that use a similar pattern. |
Just chiming in, the change was surprising for me too, but I managed to fix my project failing to build on TS 2.4.0 by sprinkling empty |
The Definitely Typed d.ts for angular should be fixed now. @evmar "add an index signature" is the easiest solution for library authors to use. If you are using a library and normally want the weak type check, you can cast to the weak type to get an exception. |
@ryanelian - your suggestion worked. I was able to do the following to get it working:
|
Why the heck would it be an OK solution to require to write an empty |
With TypeScript 2.4 a bunch of our Angular1 code produces a new error.
I reduced the code to something like the following. (The interfaces/types here are from the Angular1 d.ts on DefinitelyTyped, but I simplified them a bit to make the error more obvious.)
TypeScript 2.3 accepts this code, while 2.4 produces this error:
The error message is quite a surprise! I believe the underlying issue is that the "Demo" class is not seen to implement the IController interface anymore due to weak types, so TS picks the other union element in Injectable (the array).
I'm not sure how this can be improved, but perhaps we can think about the error?
The text was updated successfully, but these errors were encountered: