Closed
Description
openedon Dec 13, 2017
TypeScript Version: 2.6.2
Code
See also in the playground example here.
function createComponent<T>(
comp: T, inputs: Partial<T> = {}) {
for (const key in inputs) {
if (inputs.hasOwnProperty(key)) {
const partialVal = inputs[key];
const value = 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]'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment