Repository navigation
Intersection type with partial not working #16251
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScript
Milestone
Description
Activity
For minimal reproduced code and some information:
v2.4.0-dev.20170604
type X1<T> = { x: number } & { [K in keyof T]?: any }; function fn1<T>(v: X1<T> = { x: 1 }): any {}; // unexpected error // Type '{ x: number; }' is not assignable to type 'X1<T>'. // Type '{ x: number; }' is not assignable to type '{ [K in keyof T]?: any; }'. type X2<T> = { x: number } & { [K in keyof any]?: any }; function fn2<T>(v: X2<T> = { x: 1 }): any {}; // no error as expected type X3<T> = { x: number } & { [K in string]?: any }; function fn3<T>(v: X3<T> = { x: 1 }): any {}; // no error as expected
Still fails with
type X1<T extends string> = { x: number } & { [K in keyof T]?: any };(makeTexplicitly extendstring). Huh.- addedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on Aug 29, 2017 - addedBugA bug in TypeScriptA bug in TypeScriptand removedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on Aug 23, 2019 Same problem when using
Partial<T>I think:function f<T>() { // Type '{ a: 1; }' is not assignable to type '{ a: 1; } & Partial<T>'. // Type '{ a: 1; }' is not assignable to type 'Partial<T>' const x: { a: 1 } & Partial<T> = { a: 1 }; }
Just checking out old issues; this looks to have been fixed by #32071.
For the code in the recent comment, the error looks correct to me; T could be
{ a: string }in which case you're assigning tonever(or, just plain the fact that it could be undefined and it can't be1 & undefined.- locked as resolved and limited conversation to collaborators
on Oct 21, 2025
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript
TypeScript Version: 2.2.1
Code
Expected behavior:
No errors
Actual behavior: