ipatalas / vscode-postfix-ts

Postfix notation for TypeScript/Javascript - extension for VS Code
MIT License
158 stars 43 forks source link

[proposal] `.null` & `.undefined` postfixes in `if` #89

Closed zardoy closed 1 year ago

zardoy commented 2 years ago

What do you think of adding these postfixes inside if? For example:

if (b && a.null) -> if (b && a === null)

From my POV its quite common to compare something with undefined in existing if conditions

ipatalas commented 2 years ago

Yeah, that sounds possible. More over it can probably "reuse" the same null template which does different thing because only one of them should be available in particular context. Original null template won't show up inside an if statement for instance.

zardoy commented 2 years ago

Original null template won't show up inside an if statement for instance

I don't really remember how overriding works, but what is user decide to override original null template (like I did), will this special null template still be showing up? But what if someone want to disable it (to not be annoyed in binary expressions). I hope there is universal solution for this. IMO make templates more contextual overall should be main direction here!

ipatalas commented 2 years ago

I don't really remember how overriding works, but what is user decide to override original null template (like I did), will this special null template still be showing up?

Yes because the same template name can appear many times as long as canUse returns true: https://github.com/ipatalas/vscode-postfix-ts/blob/b83e0d288b296c514c10d23ea699fae01abb522b/src/postfixCompletionProvider.ts#L49-L58

But what if someone want to disable it (to not be annoyed in binary expressions). I hope there is universal solution for this. IMO make templates more contextual overall should be main direction here!

Yes, in this case it should be either one of them but not both at the same time unless there is a context when they both make sense but I don't see any now.

ipatalas commented 2 years ago

Implemented in https://github.com/ipatalas/vscode-postfix-ts/commit/3299b786704c4888086fa1b9548d77453132b52f - I've added that not only to if statements but also to return and variable assignment so you can do pretty much the same there:

return x.null // -> return x === null
const a = b.null // -> const a = b === null
ipatalas commented 1 year ago

I think I forgot to close this one :)