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
String Indexer Assignable to Generic Mapped Type #28798
// A source type T is related to a target type { [P in Q]: X } if Q is related to keyof T and T[Q] is related to X.if(!isGenericMappedType(source)&&isRelatedTo(getConstraintTypeFromMappedType(target),getIndexType(source))){constindexedAccessType=getIndexedAccessType(source,getTypeParameterFromMappedType(target));consttemplateType=getTemplateTypeFromMappedType(target);if(result=isRelatedTo(indexedAccessType,templateType,reportErrors)){returnresult;}}
In this instance we have 'a' is related string, but a type with a key set of type string is not guaranteed to have the key a. When relating keys I think string and number should really be bottom types, so a possible fix is to filter them from the source index type:
filterType(getIndexType(source),t=>!(t.flags&(TypeFlags.String|TypeFlags.Number)// and symbol??
Activity
ahejlsberg commentedon Dec 2, 2018
Jack Williams (@jack-williams) I think that is a very sensible suggestion.
jack-williams commentedon Dec 13, 2018
If this is low down on the prio list I'd be happy to give fixing this a go.
jack-williams commentedon Apr 10, 2019
Fixed here: #30769