Skip to content

Don't error when function has an implicit return but its return type is assignable to undefined - #53490

Merged
Maria Solano (MariaSolOs) merged 10 commits into
microsoft:mainfrom
MariaSolOs:undef-return-exceptions
Mar 27, 2023
Merged

Don't error when function has an implicit return but its return type is assignable to undefined#53490
Maria Solano (MariaSolOs) merged 10 commits into
microsoft:mainfrom
MariaSolOs:undef-return-exceptions

Conversation

@MariaSolOs

Copy link
Copy Markdown
Contributor

Fixes#53473

@MariaSolOs
Maria Solano (MariaSolOs) marked this pull request as ready for review March 24, 2023 20:29
Comment threadsrc/compiler/checker.ts Outdated
Comment threadsrc/compiler/checker.ts Outdated
Comment threadsrc/compiler/checker.ts Outdated
@ahejlsberg

Copy link
Copy Markdown
Member

I don't think this is the right fix for the issue. The following now doesn't error:

functionfoo(x: boolean): string|undefined{}

This previously would report "A function whose declared type is neither 'void' nor 'any' must return a value."

@ahejlsberg

Copy link
Copy Markdown
Member

The right fix is to put the assignability check back where it was originally.

@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Mar 28, 2023

Copy link
Copy Markdown
Member

Specifically, we need to undo the change I mention here. And then also undo the change in this PR.

@MariaSolOs

Copy link
Copy Markdown
ContributorAuthor

I'm confused with Jake Bailey (@jakebailey)'s comment. Is this a fix or a bug? 😄

@ahejlsberg

Copy link
Copy Markdown
Member

Is this a fix or a bug?

Is what a fix or a bug?

@MariaSolOs

Copy link
Copy Markdown
ContributorAuthor

Is what a fix or a bug?

Anders Hejlsberg (@ahejlsberg) Sorry I wasn't clear, I was referring to this PR. The way I read Jake's comment, this change fixes the issue you brought up here, but you're suggesting we undo it.

@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Mar 28, 2023

Copy link
Copy Markdown
Member

Yes, I'm suggesting we undo this PR because, while it fixes the issue here, it causes a new issue that I mention here.

The real fix is to revert the deletion of the assignability check I mention here. Once that's done there is no need for this PR.

@MariaSolOs

Copy link
Copy Markdown
ContributorAuthor

Got it, thanks for explaining! I can prepare that change.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Milestone BugPRs that fix a bug with a specific milestone

Projects

None yet

5 participants

@MariaSolOs@ahejlsberg@DanielRosenwasser@jakebailey@typescript-bot