Skip to content

Commit

Permalink
Prefer type arguments next to typeof operator
Browse files Browse the repository at this point in the history
Fixes #951, #957
  • Loading branch information
sheetalkamat committed Feb 8, 2023
1 parent 6ae8fcb commit 2f3b5b9
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,7 @@ repository:
'0': { name: keyword.operator.expression.typeof.ts }
end: (?=[,);}\]=>:&|{\?]|(extends\s+)|$|{{endOfStatement}})
patterns:
- include: '#type-arguments'
- include: '#expression'

#literals
Expand Down
4 changes: 4 additions & 0 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 4 additions & 0 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
70 changes: 70 additions & 0 deletions tests/baselines/issue951.baseline.txt
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions tests/baselines/issue957.baseline.txt
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions tests/cases/issue951.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type thing = <T extends object>(what: T) => ReturnType<typeof generic<T>>
1 change: 1 addition & 0 deletions tests/cases/issue957.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type UseQuery<TData, TVariables> = typeof useQuery<TData, TVariables>

0 comments on commit 2f3b5b9

Please sign in to comment.