Closed
Description
TypeScript Version: Nightly
Search Terms: generic spread optional property
Code
interface Test {
readonly hi?: string[]
}
function test<T extends object>(value: T): Test {
return { ...value, hi: true }
}
Expected behavior:
This should fail to type check.
Actual behavior:
It passes. Interestingly, changing any of the following causes it to fail:
- Make the
hi
property non-optional - Replace
T
withobject
.
Related Issues: Not sure