-
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
Type inference lacking on index signature types #5089
Comments
The reason for this rule was because we could not guarantee that let t2 = {thing: 'otherthing'};
t2 = {thing: 'otherotherthing', foo: 1 }
s(t2); // s is going to assume t2.foo is a string though The rule is that object literals that are contextually typed by a type with an indexer signature then get the index signature pushed into the literals type (this is what happens to let t2 = {thing: 'otherthing'};
let t3 = {thing: 'otherotherthing', foo: 1 }
t2 = t3;
s(t2); // error |
Okay, thanks for explaining. I'm almost done adding explicit types. What about this case, where I get an error, it seems like the type narrowing within the type guard should work?
|
We don't yet narrow the |
thanks, world-class support! 💐 |
Note that the previous type of StringMap was overly permissive and didn't catch errors. Also we have to explicitly type empty objects, which is explained here: microsoft/TypeScript#5089
Note that the previous type of StringMap was overly permissive and didn't catch errors. Also we have to explicitly type empty objects, which is explained here: microsoft/TypeScript#5089
Note that the previous type of StringMap was overly permissive and didn't catch errors. Also we have to explicitly type empty objects, which is explained here: microsoft/TypeScript#5089 Closes #4487
The compiler gives an error on the last line:
Index signature is missing in type '{thing: 'otherthing'}'
Which is very sad since I'm refactoring all of angular to use string index signatures instead of our hacky StringMap (angular/angular#4483)
The text was updated successfully, but these errors were encountered: