- Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
TypeScript Version: 2.2.0-dev.20161125
Code
type MapOf<T>{[x: string ]: T|never}// values only of type TtypeBox<T>{value: T}// Here we show that the above type constrains valid types for values of MapOf<T> to Tconstt: MapOf<number>={foo: 1}// compilesconsttbad: MapOf<number>={foo: 'foo'}// does not compile// assign every value of MapOf<T> to some TfunctionforMapsOf<T>(m: MapOf<T>,t: T){for(varkinm){m[k]=t}}// Compiles and works as expected// now let's transform the definition of the above function slightlyfunctionforMapsOf<T,MextendsMapOf<T>>(m: M,t: T){for(varkinm){m[k]=t}}// DOES NOT COMPILE - Says "Type T is not assignable to type M[keyof M]// The above is crucial for this function below which would take a map of // Boxed values and update them from a map of unboxed valuesfunctionupdateBoxed<T,UextendsOnly<T>,Bextends{[KinkeyofU]: Box<U[K]>}>(b: B,u: U){for(varkinu){b[k].value=u[k]}}// DOES NOT COMPILE - Says "Type U[keyof U] is not assignable to type T"Expected behavior:
I would expect the value of a type indexing itself to in-fact be all the types of its values. This should be knowable at compile-time and especially so if the type is constrained as T | never
Actual behavior:
Compiler does not recognize that U[keyof U] is the same as T.
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code