Skip to content

Interface with methods interferes with string literal type inference #19497

Closed
@wolfgang42

Description

@wolfgang42

TypeScript Version: 2.7.0-dev.20171026

Minimal example:

interface Observable<T> {peek(): T}
declare function obs<T>(val: T): Observable<T>
const t: Observable<'A'> = obs('A')

Expected behavior:
Compilation without errors.

Actual behavior:

src/test.ts(3,7): error TS2322: Type 'Observable<string>' is not assignable to type 'Observable<"A">'.
  Type 'string' is not assignable to type '"A"'.

This error goes away if the interface has no methods or function signature:

interface Observable<T> {}

Alternately, you can redundantly specify the type of the argument to obs():

const t: Observable<'A'> = obs('A' as 'A')

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