- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.1k
Closed
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 2.2.1
Code
const a: Promise<{ foo: 'bar' }> = Promise.resolve({ foo: 'typo' });
const b: Promise<{ foo: 'bar' }> = Promise.resolve({});Expected behavior:
- ashould type-check: it constrains- footo- 'bar'but is given- 'typo'.
- bshould type-check: it requires- foobut is given an object without- foo.
Actual behavior:
Neither type-check.
The same types check fine when resolved directly:
// Type '{ foo: "typo"; }' is not assignable to type '{ foo: "bar"; }'.
//   Types of property 'foo' are incompatible.
//     Type '"typo"' is not assignable to type '"bar"'.
const a: { foo: 'bar' } = { foo: 'typo' });
// Type '{}' is not assignable to type '{ foo: "bar"; }'.
//   Property 'foo' is missing in type '{}'.
const b: { foo: 'bar' } = {};Generic parameter type checks fail for objects/types of different shapes:
// Type 'Promise<{ foo: string; bar: string; }>' is not assignable to type 'Promise<{ foo: "bar"; }>'.
//   Type '{ foo: string; bar: string; }' is not assignable to type '{ foo: "bar"; }'.
//     Types of property 'foo' are incompatible.
//       Type 'string' is not assignable to type '"bar"'.
const a: Promise<{ foo: 'bar' }> = Promise.resolve({ foo: 'bar', bar: 'baz' });
// Type 'Promise<number>' is not assignable to type 'Promise<{ foo: "bar"; }>'.
//   Type 'number' is not assignable to type '{ foo: "bar"; }'.
const b: Promise<{ foo: 'bar' }> = Promise.resolve(1);niieani, ikokostya, sarenji, lucastheisen and coderitual
Metadata
Metadata
Assignees
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeFixedA PR has been merged for this issueA PR has been merged for this issue