Closed
Description
TypeScript Version: 3.9.3
Search Terms: strictNull spread
Code
// bug.ts
function useObj(obj: {foo: string, bar: number}): string {
return obj.foo;
}
interface Inter {
foo: string;
spam: number;
}
class C implements Inter {
get foo() {
return "foo string";
}
get spam() {
return 42;
}
}
function doWork(c: Inter) {
const res = useObj({...c, bar: c.spam}); // <==
console.log("res=" + res);
}
doWork(new C()); // should print "res=foo string"
Expected behavior: should print res=foo string
or result in a type error saying that property foo is undefined in the line marked with <==
Actual behavior: prints "res=undefined"
$ tsc --target ES5 --strictNullChecks bug.ts
$ node bug.js
res=undefined
Playground Link:
Related Issues: no