Skip to content

Generic object type inference #22169

@Jomik

Description

@Jomik

TypeScript Version: 2.7.2

Search Terms:
Generic object type inference
Code

class Foo<A> {
  constructor(private a: A) {}
}

type Bar<A extends object> = { [k in keyof A]: Foo<A[k]> };

class Baz<A extends object> {
  constructor(private b: Bar<A>) {}
}

const foo = new Baz({ a: new Foo<string>("foo") });
const bar = new Baz<{a: string}>({ a: new Foo<string>("bar") });

Expected behavior:
Expected foo to have type Baz<{a: string}>.

Actual behavior:
foo has type Baz<{a: any}>

Playground Link:
Typescript Playground

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions