TypeScript Version: 2.6.2
Code
See also in the playground example here.
functioncreateComponent<T>(comp: T,inputs: Partial<T>={}){for(constkeyininputs){if(inputs.hasOwnProperty(key)){constpartialVal=inputs[key];constvalue=partialVal!;comp[key]=value;}}}Expected behavior:
parialVal! should strip the |undefined from value, and the assignment should succeed.
Actual behavior:
Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'.
Type 'undefined' is not assignable to type 'T[keyof T]'.
Type 'undefined' is not assignable to type 'T[string]'.
Type 'Partial<T>[keyof T]' is not assignable to type 'T[string]'.
Type 'T[keyof T] | undefined' is not assignable to type 'T[string]'.
Type 'undefined' is not assignable to type 'T[string]'.
TypeScript Version: 2.6.2
Code
See also in the playground example here.
Expected behavior:
parialVal!should strip the|undefinedfrom value, and the assignment should succeed.Actual behavior: