vscode-postfix-ts
vscode-postfix-ts copied to clipboard
Incorrect type snippet inserting with indexed access
I have .t snippet that I use to wrap types into generics e.g. SomeType.t -> Partial<SomeType>, its really handy. However, I usually use it in combination with Extract so I can reduce amount of fields passing to the generic above e.g. Partial.
Snippet:
{
"name": "t",
"description": "",
"body": "$1<{{expr}}>$2",
"when": ["type"]
}
Works:
Extract<Config.t, ''> -> Extract<<Config>, ''>
Fails:
Extract<Config[''].t, ''> -> <Extract<Config['']>, ''> // notice incorrect insertion of opening <
The same applies for typeof:
Partial<Extract<typeof config.t, ''>> -> Partial<<Extract<typeof config>, ''>>
Expected:
Partial<Extract<typeof config.t, ''>> -> Partial<Extract<<typeof config>, ''>>
Hope I made it clear.
The last two examples also "fails" without Partial, just added it to demonstrate where exactly it inserts <. I find this behavior is inconsistent.
I admit I haven't been using generics too much so officially it's not supported. If it works then by coincidence :)
First two however seem to work as expected:

This might be tricky to get full support but I'll have a look on the AST of generics.
Hey, @ipatalas regarding type snippets, is this by design that identifier postfixes are suggested in type references?
For example:
only type suggestions: type a = null
type & identifier suggestions: type a = a
in ast it's still a valid Identifier, but as I understand they should be suggested for variableNames only
Well, the identifier condition is basically a map to TS identifier in AST and Type is also an identifier:

I can see that README does not specify that very clearly and your interpretation makes absolute sense. The change should be relatively simple but it may be a breaking change for some users so I need to think if it's not gonna be a big deal.