ipatalas / vscode-postfix-ts

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

"when" on TypeScript types #41

Closed vladdeSV closed 3 years ago

vladdeSV commented 3 years ago

I have a snippet for TypeScript which "promisifies" values, and it works great for custom types

- MyType.promisify
+ Promise<MyType>

However, I cannot target built-in types such as boolean, void, etc. in "when": [...].

vladdeSV commented 3 years ago

As of right now, I have only specified identifier, which mean the postfix does not appear on the built-in types. My attempt to remedy this was to remove any criteria ("when": [],), but that caused other unexpected behavior when applying to return types

- public ping = async (): boolean.promisify=> {
+ public ping = Promise<async (): boolean> => {
  // ...
}
ipatalas commented 3 years ago

Hi. Thanks for reporting. There is no way to make it work in current version. The underlying engine is slightly broken in that matter. Luckily It's not that hard to fix it so I'm gonna fix it in next release. I already have a semi-working version - still trying few edge cases.

I like the idea of this snippet so much that I'd like to include it as built-in snippet if you don't mind - what do you say?

ipatalas commented 3 years ago

As a side effect of that change I will be finally able to fine tune some of the snippets so that they don't show in type context. const x : boolean.log didn't make much sense. Many other snippets suffer the same but so far I though it will be more effort to fix that. Thanks for inspiration.

vladdeSV commented 3 years ago

what do you say?

That will be a great addition! Looking forward to the next release 😋

ipatalas commented 3 years ago

Ok, the release is out! Enjoy :)

Added additional when option: type which can be used for other custom templates like this but you should not need this for promisify as this is also a new built-in template :)