Skip to content

Reassigned types ignored after return #47153

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
oliver-ni opened this issue Dec 14, 2021 · 2 comments
Closed

Reassigned types ignored after return #47153

oliver-ni opened this issue Dec 14, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@oliver-ni
Copy link

Bug Report

πŸ”Ž Search Terms

  • return
  • early return

πŸ•— Version & Regression Information

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

⏯ Playground Link

Playground Link

πŸ’» Code

const a = (s: string) => {}

const b = (s: string | number) => {
  s = "";
  return;
  a(s);  // <- Error occurs here (type 'number' is not assignable to type 'string')
}

const c = (s: string | number) => {
  s = "";
  a(s);  // <- No error here
}

πŸ™ Actual behavior

On the line a(s); in the function b:

Argument of type 'string | number' is not assignable to parameter of type 'string'.
  Type 'number' is not assignable to type 'string'.

Type error is thrown even though s is reassigned as a string before the call.

πŸ™‚ Expected behavior

No type error.

Without the return, as in the function c, everything works as expected.

Not sure whether this is intended or not, but seems like a bug to me. Thanks!

@RyanCavanaugh
Copy link
Member

See #26914

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Dec 14, 2021
@oliver-ni
Copy link
Author

Ahh, thanks. Missed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants