microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.42k stars 12.41k forks source link

Boolean intellisense #29973

Open ghost opened 5 years ago

ghost commented 5 years ago

Intellisense is great for things like typeof, so why not make it great for boolean types too!

I think adding intellisense for booleans saves a bit of typing, and it still hasn't been implemented.

Look at this:

const a = (): boolean => true;
a() === // [true, false] intellisense prompt
const b = a();

if (b === /* [true, false] intellisense prompt*/) 

I think this would be a great addition to Intellisense. Any feedback is appreciated.

mjbvz commented 5 years ago

The right hand side could also be an expression, such as:

a() === x

or:

a() === new Namespace.MyClass().enabled()

We do have the concept of recommend suggestions, so we could recommend true and false so that they are preselected in the suggestion list. I'm not sure how helpful this would be in practice.

Moving upstream for more feedback

ghost commented 5 years ago

It's better for "hunt 'n' peckers" (people that are terrible at using the keyboard) but it looks like a good feature, and sometimes I'm in a bit of a rush when it's the night, so this would be a helpful feature in my opinion.

DanielRosenwasser commented 5 years ago

Apart from loose equality, why would you write either

x === true
x !== true

instead of the following?

x
!x
ghost commented 5 years ago

@DanielRosenwasser It's more explicit, and it avoids the quirks of JavaScript.

function a (b, c) {
    if (b === true) return b;
    if (c === true) return c;
}

a(1, true) // => c
a(true, 1) // => b
RyanCavanaugh commented 5 years ago

Probably the best UX upside is that if you write if (foo() === thinking foo returned some other type, you'd see true/false in the completion list and immediately know what was up