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
anything is assignable to T[P] where T extends null/undefined/void/object/never #15371
exportfunctiononeOrAnother<A,B>(one: A,another: B): A|B{returnMath.random()>0.5 ? one : another;}exportfunctiontest<Textendsobject,PextendskeyofT>(whatever: T,name: P): T[P]{constresult=oneOrAnother(whatever[name],'Hello!');// <-- result is clearly string | T[P] as expectedreturnresult;// <-- expected a type error, actual returning string | T[P] instead of T[P] no problem}
You probably already found this out but these issues arise from extending object.
What one gains from extending object and why these issues arise when you do it is beyond me however.
changed the title [-]T[P] | string should not be assignable to T[P][/-][+]T[P] | string should not be assignable to T[P] where T extends object[/+]on Aug 16, 2017
changed the title [-]T[P] | string should not be assignable to T[P] where T extends object[/-][+]string should not be assignable to T[P] where T has a type constraint[/+]on Aug 16, 2017
changed the title [-]string should not be assignable to T[P] where T has a type constraint[/-][+]string should not be assignable to T[P] where T has a primitive type constraint[/+]on Aug 16, 2017
Activity
MrAndersen1 commentedon May 3, 2017
You probably already found this out but these issues arise from extending object.
What one gains from extending object and why these issues arise when you do it is beyond me however.
[-]unsound value picking from mapped types[/-][+]T[P] | string should not be assignable to T[P][/+][-]T[P] | string should not be assignable to T[P][/-][+]T[P] | string should not be assignable to T[P] where T extends object[/+]sandersn commentedon Aug 16, 2017
Here's a smaller repro:
[-]T[P] | string should not be assignable to T[P] where T extends object[/-][+]string should not be assignable to T[P] where T has a type constraint[/+][-]string should not be assignable to T[P] where T has a type constraint[/-][+]string should not be assignable to T[P] where T has a primitive type constraint[/+]7 remaining items
Fix #17069 and #15371
sandersn commentedon Aug 18, 2017
The previous PR got merged by mistake and is now reverted; #17912 is the PR with the fix now.
zpdDG4gta8XKpMCd commentedon Jan 11, 2018
looks like this pr might be the reason to #12215 (comment)