Skip to content

Nested object type inference #25295

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Jomik opened this issue Jun 28, 2018 · 3 comments
Closed

Nested object type inference #25295

Jomik opened this issue Jun 28, 2018 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@Jomik
Copy link

Jomik commented Jun 28, 2018

TypeScript Version: 3.0.0-dev.20180628

Search Terms: infer nested type object

Code

class Foo<A> {
  private a: A;
}

class ObjectFoo<A> extends Foo<A> {
  constructor(private b: { [k in keyof A]: Foo<A[k]> }) {
    super();
  }
}

const a = new ObjectFoo({ b: new Foo<string>() });
const obj = new ObjectFoo({ a });

Expected behavior:
Expect obj to have type { a: { b: string } }

Actual behavior:
obj has type { a: { b: any } }

Playground Link:
playground

Related Issues:

@RyanCavanaugh
Copy link
Member

This is just a bug in the typeToString code; the actual type of b is string

Duplicate of #23897

@Jomik
Copy link
Author

Jomik commented Jun 28, 2018

@RyanCavanaugh so the actual type is inferred for multiple layers of nested objects? :)
Thank you, I will follow that issue, feel free to close this!

@RyanCavanaugh
Copy link
Member

Yep, you can try in the Playground - the properties of string will show up on obj.a.a.b (once you remove the private modifier)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants