Conflicting intersections
Concept and syntax
When two intersected object contracts require incompatible types for the same property, that property can become never. For example number & string admits no ordinary value. Intersections do not choose the last property type. Redesign conflicting contracts or use a union if alternatives are intended. Conflict["id"] is an indexed access type: it extracts the declared id property type (covered in the later type-operator chapter).
Working example
Save each snippet separately as main.ts in a fresh directory. Compile with tsc --strict --target ES2022 --module commonjs --moduleDetection force --skipLibCheck --noEmitOnError main.ts, then run the accepted example with node main.js. Forced module detection isolates snippet names from global declarations.
type Conflict = {id:number} & {id:string};type Id = Conflict["id"];function impossible(x:Id):never { return x; }const item:{id:number} & {label:string} = {id:1,label:"ok"};console.log(item.label);Expected output:
okThe function impossible has no ordinary callable input: the property type must satisfy both number and string. The actual log comes from the separate compatible object.
Common mistake
Intentionally invalid; compile separately and do not execute.
type Conflict = {id:number} & {id:string};const item:Conflict = {id:1};Expected diagnostic: TS2322. id would need to satisfy both primitive types; use a single consistent id contract.
Practice and recap
Replace the conflicting property with two differently named fields.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Conflicting intersections — knowledge check
Check the contract, trace output, and diagnose an invalid example.
Which statement about this lesson’s concept is accurate?
What is the complete stdout, represented as a JSON string (including newline characters)?
type Conflict = {id:number} & {id:string};type Id = Conflict["id"];function impossible(x:Id):never { return x; }const item:{id:number} & {label:string} = {id:1,label:"ok"};console.log(item.label);Which diagnostic and explanation match the rejected example under the lesson settings?
type Conflict = {id:number} & {id:string};const item:Conflict = {id:1};