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

💅 Unexpected removal of type with rule noInferrableTypes #727

Closed
1 task done
rubiesonthesky opened this issue Nov 14, 2023 · 5 comments · Fixed by #729
Closed
1 task done

💅 Unexpected removal of type with rule noInferrableTypes #727

rubiesonthesky opened this issue Nov 14, 2023 · 5 comments · Fixed by #729
Assignees
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug S-Needs discussion Status: needs a discussion to understand criteria

Comments

@rubiesonthesky
Copy link

Environment information

CLI:
  Version:                      1.3.3
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.9.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/10.2.2"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    true
  VCS disabled:                 true

Workspace:
  Open Documents:               0

Rule name

noInferrableTypes

Playground link

https://biomejs.dev/playground/?code=ZgB1AG4AYwB0AGkAbwBuACAAZABvAFMAbwBtAGUAdABoAGkAbgBnACgAcABhAHIAYQBtADEAOgAgAHMAdAByAGkAbgBnACAAPQAgAG4AdQBsAGwAKQAgAHsACgAgACAACgB9AA%3D%3D

Expected result

: string should not be removed and the code should stay like it was.

function doSomething(param1: string = null) {}

Removing type form param1 will make its type to be any. If Typescript project would have strictNullChecks enabled, then this would not be a problem because there would be a type error with the existing code. But in project, where that is disabled, above code is valid.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@ematipico
Copy link
Member

ematipico commented Nov 14, 2023

Indeed, Biome shouldn't provide the suggestion, although this comes from code that even TypeScript doesn't like.

At the moment Biome can't understand the TypeScript configuration, so I'm not sure about what the rule should do in this case. Probably we should do more narrow checking of what's on the right of the assignment.

@ematipico ematipico added A-Linter Area: linter S-Needs discussion Status: needs a discussion to understand criteria labels Nov 14, 2023
@rubiesonthesky
Copy link
Author

Typescript is fine with the code with correct settings: Typescript playground

@Conaclos Conaclos added L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels Nov 14, 2023
@rubiesonthesky
Copy link
Author

rubiesonthesky commented Nov 14, 2023

I think, if the value is null or undefined, the rule should never remove the type unless the type is exactly same.

function doSomething(param1: null = null) {}

could be changed to

function doSomething(param1 = null) {}

But I think that in that case too, it would be better to left it alone.

Typescript Eslint does not complain about this with their similar rule. no-inferrable-types Typescript Eslint playground

@Conaclos
Copy link
Member

Thanks for the reporting :)

@Conaclos
Copy link
Member

At the moment Biome can't understand the TypeScript configuration, so I'm not sure about what the rule should do in this case. Probably we should do more narrow checking of what's on the right of the assignment.

Yes, I think we should assume that TypeScript is in the unsafe null mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug S-Needs discussion Status: needs a discussion to understand criteria
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants