Skip to content
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

Infer generic types based on properties #7496

Closed
DavidKDeutsch opened this issue Mar 13, 2016 · 1 comment
Closed

Infer generic types based on properties #7496

DavidKDeutsch opened this issue Mar 13, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@DavidKDeutsch
Copy link

This may be a duplicate of #7234 and/or #3812, but I don't know enough about the internals of TypeScript to know for sure. Let's say I have the following:

interface MyInfo<T> {
   data: T;
}

class Foo {
   x: number;
} 

let fooInfos: MyInfo<Foo>[];
let objectInfos: MyInfo<Object>[];

for (let info of objectInfos) {
   if (info.data instanceof Foo) {
       fooInfos.push(info); // should infer that info is MyInfo<Foo>, but it doesn't
   }
} 

In this case, the compiler still thinks info is of type MyInfo<Object> instead of MyInfo<Foo>, whereas I would expect it to be able to properly infer the type.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 28, 2016

this is a duplicate of #3812.

@mhegazy mhegazy closed this as completed Mar 28, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Mar 28, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants