Prefer type arguments next to typeof operator

Fixes #951, #957
This commit is contained in:
Sheetal Nandi 2023-02-08 15:23:40 -08:00
Родитель 6ae8fcb18b
Коммит 2f3b5b963c
7 изменённых файлов: 135 добавлений и 0 удалений

Просмотреть файл

@ -1768,6 +1768,7 @@ repository:
'0': { name: keyword.operator.expression.typeof.ts }
end: (?=[,);}\]=>:&|{\?]|(extends\s+)|$|{{endOfStatement}})
patterns:
- include: '#type-arguments'
- include: '#expression'
#literals

Просмотреть файл

@ -5747,6 +5747,10 @@
<string>(?=[,);}\]=&gt;:&amp;|{\?]|(extends\s+)|$|;|^\s*$|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#type-arguments</string>
</dict>
<dict>
<key>include</key>
<string>#expression</string>

Просмотреть файл

@ -5693,6 +5693,10 @@
<string>(?=[,);}\]=&gt;:&amp;|{\?]|(extends\s+)|$|;|^\s*$|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#type-arguments</string>
</dict>
<dict>
<key>include</key>
<string>#expression</string>

Просмотреть файл

@ -0,0 +1,70 @@
original file
-----------------------------------
type thing = <T extends object>(what: T) => ReturnType<typeof generic<T>>
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>type thing = <T extends object>(what: T) => ReturnType<typeof generic<T>>
^^^^
source.ts meta.type.declaration.ts storage.type.type.ts
^
source.ts meta.type.declaration.ts
^^^^^
source.ts meta.type.declaration.ts entity.name.type.alias.ts
^
source.ts meta.type.declaration.ts
^
source.ts meta.type.declaration.ts keyword.operator.assignment.ts
^
source.ts meta.type.declaration.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts
^^^^^^^
source.ts meta.type.declaration.ts meta.type.parameters.ts storage.modifier.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts
^^^^^^
source.ts meta.type.declaration.ts meta.type.parameters.ts support.type.builtin.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^^^^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.type.declaration.ts
^^
source.ts meta.type.declaration.ts meta.type.function.return.ts storage.type.function.arrow.ts
^
source.ts meta.type.declaration.ts meta.type.function.return.ts
^^^^^^^^^^
source.ts meta.type.declaration.ts meta.type.function.return.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.function.return.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^^^^^^
source.ts meta.type.declaration.ts meta.type.function.return.ts meta.type.parameters.ts keyword.operator.expression.typeof.ts
^
source.ts meta.type.declaration.ts meta.type.function.return.ts meta.type.parameters.ts
^^^^^^^
source.ts meta.type.declaration.ts meta.type.function.return.ts meta.type.parameters.ts variable.other.readwrite.ts
^
source.ts meta.type.declaration.ts meta.type.function.return.ts meta.type.parameters.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^
source.ts meta.type.declaration.ts meta.type.function.return.ts meta.type.parameters.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.function.return.ts meta.type.parameters.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.type.declaration.ts meta.type.function.return.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts

Просмотреть файл

@ -0,0 +1,54 @@
original file
-----------------------------------
export type UseQuery<TData, TVariables> = typeof useQuery<TData, TVariables>
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>export type UseQuery<TData, TVariables> = typeof useQuery<TData, TVariables>
^^^^^^
source.ts meta.type.declaration.ts keyword.control.export.ts
^
source.ts meta.type.declaration.ts
^^^^
source.ts meta.type.declaration.ts storage.type.type.ts
^
source.ts meta.type.declaration.ts
^^^^^^^^
source.ts meta.type.declaration.ts entity.name.type.alias.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^^^^^
source.ts meta.type.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.separator.comma.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts
^^^^^^^^^^
source.ts meta.type.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.type.declaration.ts
^
source.ts meta.type.declaration.ts keyword.operator.assignment.ts
^
source.ts meta.type.declaration.ts
^^^^^^
source.ts meta.type.declaration.ts keyword.operator.expression.typeof.ts
^
source.ts meta.type.declaration.ts
^^^^^^^^
source.ts meta.type.declaration.ts variable.other.readwrite.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^^^^^
source.ts meta.type.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.separator.comma.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts
^^^^^^^^^^
source.ts meta.type.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts

1
tests/cases/issue951.ts Normal file
Просмотреть файл

@ -0,0 +1 @@
type thing = <T extends object>(what: T) => ReturnType<typeof generic<T>>

1
tests/cases/issue957.ts Normal file
Просмотреть файл

@ -0,0 +1 @@
export type UseQuery<TData, TVariables> = typeof useQuery<TData, TVariables>