Skip to content

Type alias resolves to different type than placing the type inline #15973

Closed
@LennyLixalot

Description

@LennyLixalot

TypeScript Version: 2.3.1, VS 2017 Preview 2

Code

// A *self-contained* demonstration of the problem follows...
type S = { items: {whatever:true}};
type ExtractedItems<T> = ({[K in keyof (T | { items: {} })]: { [key: string]: T[K] }} & { items: {} })["items"];
let extractedInline:     ({[K in keyof (S | { items: {} })]: { [key: string]: S[K] }} & { items: {} })["items"];
let extractedWithType: ExtractedItems<S>;

Expected behavior:
extractedInline and extractedWithType should have the same type.
Actual behavior:
extractedInline is typed as expected, extractedWithType is typed as {}.

image

image

If this behaviour IS in some way expected, that's not made clear in the documentation. Our natural assumption is that a type alias used in this manner to provide a level of indirection should not change the type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions