No ts 2352 for object literal with missing properties
Bug Report
🔎 Search Terms
google search
site:github.com/microsoft/TypeScript/issues ("ts(2352)" OR "TS2352" OR "neither type sufficiently overlaps" OR "as unknown") ("instanceof" OR "typeof" OR "narrowing" OR "type guard") " as "
🕗 Version & Regression Information
- Tested v5.0.4
- Tested nightly
⏯ Playground Link
Playground link with relevant code
💻 Code
interface ITest {
first: number;
second: string;
}
// No error on this as ITest
const foo = {
first: 2
} as ITest;
🙁 Actual behavior
No codefix.
🙂 Expected behavior
Codefix to convert to 0 as unknown as string. ts(2352)
This is working as intended. You instruct the compiler to consider your incomplete object as a ITest using the type assertion. The types overlap, so no temporary as unknown step is necessary.
When I change first's type to string. I started to get ts(2352) That's what confused me.
const foo = {
first: 'string'
} as ITest;
This issue can be closed if works as intended.
When you change it to string you don't have it overlapping anymore, there's no common property.