TypeScript Version: 2.1.4
Code
functionget<T,KextendskeyofT,K2extendskeyofT[K]>(obj: T,propertyName: K,propertyName2: K2): T[K][K2]|undefined{conststep1=obj ? obj[propertyName] : undefined;returnstep1 ? step1[propertyName2] : undefined;}interfaceOrg{admin?: User;}interfaceUser{email?: string;}consto: Org={admin: {email: 'foo'}};consto2: Org={};console.log(get(o,'admin','email'))console.log(get(o2,'admin','email'))Expected behavior:
Expect to output:
Actual behavior:
with strictNullChecks, fails to compile:
foo.ts(17,29): error TS2345: Argument of type '"email"' is not assignable to parameter of type 'never'.
foo.ts(18,30): error TS2345: Argument of type '"email"' is not assignable to parameter of type 'never'.
works without strictNullChecks:
TypeScript Version: 2.1.4
Code
Expected behavior:
Expect to output:
Actual behavior:
with strictNullChecks, fails to compile:
works without strictNullChecks: