Closed
Description
The following cases can all be converted to foo ?? 'a string'
.
const foo: any = 'bar';
foo !== undefined && foo !== null ? foo : 'a string';
foo === undefined || foo === null ? 'a string' : foo;
const foo:? string = 'bar';
foo !== undefined ? foo : 'a string';
foo === undefined ? 'a string' : foo;
const foo: string | null = 'bar';
foo !== null ? foo : 'a string';
foo === null ? 'a string' : foo;
This is even hinted at in the docs, but sadly currently not covered.
Supporting foo ? foo : 'a string'
would create conflicts with no-unneeded-ternary
which is why I'm against doing so.
I can have a look at creating a PR if there is interest for this.