8000 Type Inference does not work for generics with default types · Issue #19205 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Type Inference does not work for generics with default types #19205
Closed
@jpkraemer

Description

@jpkraemer

TypeScript Version: 2.6.0-dev.201xxxxx

Code

type FormattedDataProvider<T, R = {}> = {
  src: R,
  format: (item: R) => T
}

let a: FormattedDataProvider<string> = {
  src: { a: 23 },
  format: v => String(v.a)
}

Expected behavior:

This should compile and infer that v is of type {a: number}.

Actual behavior:
v is inferred to the default type {}, which results in an error:
error TS2339: Property 'a' does not exist on type '{}'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0