Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kermanx opened this issue Jan 20, 2024 · 0 comments Β· Fixed by #57341
Closed

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

kermanx opened this issue Jan 20, 2024 · 0 comments Β· Fixed by #57341
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@kermanx
Copy link

kermanx commented Jan 20, 2024

πŸ”Ž 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.

@kermanx kermanx changed the title this is return type of member function isn't checked when implementing or inheriting this is return type of member function isn't checked when implementing Jan 24, 2024
@kermanx kermanx changed the title this is return type of member function isn't checked when implementing this is return type of method isn't checked when implementing Jan 30, 2024
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Feb 1, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants