Skip to content

Intellisense and generated declarations emit wrong types (mapped types) #14041

@gcanti

Description

@gcanti

TypeScript Version: 2.1.5, 2.1.6, 2.2.0-dev20170203

VS Code Version: 1.9.1

Code

class Type<T> { t: T }

type TypeOf<T extends Type<any>> = T['t'];

type Props = { [key: string]: Type<any> };

declare function obj<P extends Props>(props: P): Type<{ [K in keyof P]: TypeOf<P[K]> }>;

const str = new Type<string>()

const A = obj({
  a: str
})

type TypeOfA = TypeOf<typeof A> // => Intellisense correctly shows { a: string }

const B = obj({
  b: obj({
    c: str
  })
})

type TypeOfB = TypeOf<typeof B> // => should be { b: { c: string } } but Intellisense shows { b: any; }

// though the inferred type seems correct
const b1: TypeOfB = {} // error
const b2: TypeOfB = { b: {} } // error
const b3: TypeOfB = { b: { c: 'foo' } } // NO error

Expected behavior:

Intellisense should show

type TypeOfB = {
  b: {
    c: string
  };
}

Actual behavior:

Intellisense shows

type TypeOfB = {
  b: any;
}

EDIT: detail screenshot

intellisense

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions