Skip to content

this is return type of method isn't checked when implementingΒ #57103

Closed
@kermanx

Description

@kermanx

πŸ”Ž Search Terms

"this is type", "return type", "implement", "inherit", "not checked"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "this is"

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.3#code/JYOwLgpgTgZghgYwgAgILIN4ChnILYRgAWA9gCYCMAFAJQBcyxwAzsi5jrsnAxZwL6cCxcgCZaDAEYkSAGwhwQAbiyCEsuM1YAhNngAO8guFbpsuAPQXkAdSIBPZCBLJoUElAD8QwqUq1MZEFOK2QAATBmAFoIAA99CAQwGKh3KGQAFXsE5AByADcSYDJctlZnMG4tYABzEDhJeUYXMGyUXOk5BRBcnxEycRpAwWDWnIzkAF5kACVCAFcoECyEgB4ASRBmMEUkFYhVsYgSGGRtAD4AbQAiYT8Ka4Bdc6wgA

πŸ’» Code

interface A {
  method1(): this is {
    a: 1
  };
  method2(): boolean;
}
class B implements A {
  // Why no error?
  method1() { }

  // @ts-expect-error Type 'void' is not assignable to type 'boolean'
  method2() { }
}

πŸ™ Actual behavior

B.method1 produces no error, and its return type is void.

πŸ™‚ Expected behavior

B.method1 should be an error.

Additional information about the issue

If A in the above example is a class, and B is extending A, this bug will also happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions