-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
FixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: nightly (2.2.0-dev.20161204)
Code
type T1 = {a?: number};
let o1: T1 = {a: 'no'}; // error: Type '{ a: string; }' is not assignable to type 'T1'
let p1: Partial<T1> = {a: 'no'}; // same error
type T2 = {a?: number, [key: string]: any};
let o2: T2 = {a: 'no'}; // error: Type '{ a: string; }' is not assignable to type 'T2'
let p2: Partial<T2> = {a: 'no'}; // ok - expected same error
let p3: {[P in keyof T2]: T2[P]} = {a: 'no'}; // also ok - expected same errorExpected behavior:
Applying Partial<T> to a type T that has an index signature should not modify the expected property types. The issue is the same regardless of whether the properties of T are optional or not and for the identity type mapping {[P in keyof T]: T[P]}.
The problem seems to be that the type mapping elevates the index signature to a higher priority in the mapped type than in the original type.
Actual behavior:
Partial<T & {[key: string]: any}> is identical to {[key: string]: any} for all types T, making Partial useless for types that have an index signature.
Metadata
Metadata
Assignees
Labels
FixedA PR has been merged for this issueA PR has been merged for this issue