Skip to content

Inferred type shows up incorrectly in error messages and on hover (but type checking seems to be okay) #21638

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

Closed
univerio opened this issue Feb 5, 2018 · 6 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@univerio
Copy link

univerio commented Feb 5, 2018

TypeScript Version: 2.7.1, 2.8.0-dev.20180204

Search Terms: type inference, indexed type

Code

declare function foo<T>(attrs: {[K in keyof T]: T[K]}): T;
let res = foo({id: ""});
res = foo({id: 1});

Expected behavior:

The error should be (as in 2.6)

index.ts(3,1): error TS2322: Type '{ id: number; }' is not assignable to type '{ id: string; }'.
  Types of property 'id' are incompatible.
    Type 'number' is not assignable to type 'string'.

Actual behavior:

The error is

index.ts(3,1): error TS2719: Type '{ id: any; }' is not assignable to type '{ id: any; }'. Two different types with this name exist, but they are unrelated.
  Types of property 'id' are incompatible.
    Type 'number' is not assignable to type 'string'.

And the reported type on hover is also not correct

image

Playground Link: link

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 5, 2018
@mhegazy mhegazy added this to the TypeScript 2.8 milestone Feb 5, 2018
@weswigham
Copy link
Member

Maybe a duplicate of #21382? It's very similar, at least.

@weswigham
Copy link
Member

Wait, no @mhegazy this is just the expected behavior for a deferred inferred type - right @sandersn?

@sandersn
Copy link
Member

sandersn commented Feb 6, 2018

Yes, I have a fix at #21311. Please review!

@sandersn
Copy link
Member

sandersn commented Feb 6, 2018

It's 50% smaller now that the display builder is gone, too.

@weswigham
Copy link
Member

@sandersn This issue should be marked as fixed now, right?

@sandersn
Copy link
Member

Yes. Good catch.

@sandersn sandersn added the Fixed A PR has been merged for this issue label Feb 27, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants