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

New rule: LHS of nullish coalescing operator (??) should be nullable #16

Open
bondo opened this issue Jan 18, 2021 · 4 comments
Open

New rule: LHS of nullish coalescing operator (??) should be nullable #16

bondo opened this issue Jan 18, 2021 · 4 comments

Comments

@bondo
Copy link
Member

bondo commented Jan 18, 2021

This should give a linting error

const x = 42 ?? 60;

and this

async function foo(): Promise<number|null> {
  return null;
}
async function bar(): Promise<number|null> {
  return foo() ?? 42;
}
@bondo
Copy link
Member Author

bondo commented Jan 18, 2021

I'm think this could realistically become an issue when changing foo from function foo(): number|null to async function foo(): Promise<number|null>

@kastermester
Copy link
Member

I think this should simply be a check that ?? is only applied to something that is nullable. I think that would be of greater general use. Maybe there's something out there already that does this?

@bondo
Copy link
Member Author

bondo commented Jan 19, 2021

After a little bit of searching I can't find this anywhere, either for TSLint or ESLint

@kastermester
Copy link
Member

Alright, then we should probably make this ourselves. Can you fix the issue title, etc? :)

@bondo bondo changed the title proper-promise-use: Check await of LHS of nullish coalescing operator (??) New rule: LHS of nullish coalescing operator (??) should be nullable Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants