You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
non-null assertion on TypeParameter changes string | undefined to String #21360
declarefunctionfoo(p: string): void;functionfn<Textendsstring|undefined,Uextendsstring>(one: T,two: U){letthree=Boolean() ? one : two;foo(one!);foo(two!);foo(three!);// error on this line}
Expected behavior:
No type error.
Actual behavior:
Argument of type 'string | String' is not assignable to parameter of type 'string'.
Type 'String' is not assignable to type 'string'.
'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.
This is caused by #20995. To be fair, without that change the above was not valid at all.
getApparentTypeForLocation (which is how we enabled this, similarly to how we've made guards on this.foo.bar work when this.foo is an indexed access type) uses getAparrentType. That replaces primitives with their corresponding interfaces; I don't think we (ever) actually want do do that here (it just didn't matter when it was only ever used for the left hand side of a property access), so it's probably appropriate to factor out the constraint-mapping behaviors and perform only that here.
Activity
ahejlsberg commentedon Jan 24, 2018
Wesley Wigham (@weswigham)
weswigham commentedon Jan 24, 2018
getApparentTypeForLocation(which is how we enabled this, similarly to how we've made guards onthis.foo.barwork whenthis.foois an indexed access type) usesgetAparrentType. That replaces primitives with their corresponding interfaces; I don't think we (ever) actually want do do that here (it just didn't matter when it was only ever used for the left hand side of a property access), so it's probably appropriate to factor out the constraint-mapping behaviors and perform only that here.