Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Class method with conditional return type cannot return types common to both conditional branches when the class also has an interfaceΒ #50822

Copy link
Copy link
@ascott18

Description

@ascott18
Issue body actions

Bug Report

πŸ”Ž Search Terms

method conditional return type not assignable to type

πŸ•— Version & Regression Information

3.3.3+

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

export interface Foo<T> {}
export class Foo<T> {
  public bar(): T extends string ? string | number : number {
    return 1;
  }
}

πŸ™ Actual behavior

Return statement is an error, despite being valid for both branches of the conditional return type.

This ONLY happens if the interface Foo exists. If the interface is commented out, the error goes away.

πŸ™‚ Expected behavior

Return statement is not an error, because 1 is assignable to both string | number and number.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional types

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.