-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Intersection type with partial not working #16251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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 |
Same problem when using 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 |
TypeScript Version: 2.2.1
Code
Expected behavior:
No errors
Actual behavior:
The text was updated successfully, but these errors were encountered: