镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Interface with methods interferes with string literal type inference #19497

Description

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')

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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