Skip to content
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

any | T from conditional type does not reduce to any #52568

Closed
dragomirtitian opened this issue Feb 2, 2023 · 1 comment Β· Fixed by #52573
Closed

any | T from conditional type does not reduce to any #52568

dragomirtitian opened this issue Feb 2, 2023 · 1 comment Β· Fixed by #52573
Assignees
Labels
Domain: Conditional Types The issue relates to conditional types Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this

Comments

@dragomirtitian
Copy link
Contributor

Bug Report

πŸ”Ž Search Terms

any union

πŸ•— Version & Regression Information

  • This changed between versions 5.0.0-dev.20221207 and 5.0.0-dev.20221208

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Spec = any extends object ? any : string;

type WithSpec<T extends number> = T

type R = WithSpec<Spec> // error here  in 5.0

πŸ™ Actual behavior

Spec is any | string so it can't be used with WithSpec

πŸ™‚ Expected behavior

any | string is reduced to any as it was in 4.9

@Tobias-Scholz
Copy link
Contributor

I believe this is caused by #50397 and #51621.

In 4.9 we had a check in getSubstitutionType where the baseType was returned when both baseType and constraint where non-generic. This check was removed in #51621, so a SubstitutionType is created for any.

A simple fix might be to just return the baseType when the baseType is any.

function getSubstitutionType(baseType: Type, constraint: Type) {
  if (constraint.flags & TypeFlags.AnyOrUnknown || constraint === baseType || baseType.flags & TypeFlags.Any) {
    return baseType;
  }

@DanielRosenwasser DanielRosenwasser added Help Wanted You can do this Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Domain: Conditional Types The issue relates to conditional types labels Feb 2, 2023
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.0.1 milestone Feb 2, 2023
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Conditional Types The issue relates to conditional types Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants