Support type arguments after typeof (#15466)
This commit is contained in:
1 parent
c140ed6b53
commit
fa8cb85434
7 files changed
+32
-6
No files matched your search
@@ -0,0 +1,8 @@
|
||||
#### Support type arguments after `typeof` (#15466 by @sosukesuzuki)
|
||||
|
||||
Supports type arguments after `typeof` syntax supported since [Flow v0.127.0](https://github.com/facebook/flow/blob/HEAD/Changelog.md#02170):
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```jsx
|
||||
type Foo = typeof MyGenericClass<string, number>;
|
||||
```
|
||||
@@ -521,12 +521,11 @@ function printArrayType(print) {
|
||||
- `TypeofTypeAnnotation`
|
||||
*/
|
||||
function printTypeQuery({ node }, print) {
|
||||
return [
|
||||
"typeof ",
|
||||
...(node.type === "TSTypeQuery"
|
||||
? [print("exprName"), print("typeParameters")]
|
||||
: [print("argument")]),
|
||||
];
|
||||
const argumentPropertyName =
|
||||
node.type === "TSTypeQuery" ? "exprName" : "argument";
|
||||
const typeArgsPropertyName =
|
||||
node.type === "TSTypeQuery" ? "typeParameters" : "typeArguments";
|
||||
return ["typeof ", print(argumentPropertyName), print(typeArgsPropertyName)];
|
||||
}
|
||||
|
||||
function printTypePredicate(path, print) {
|
||||
|
||||
@@ -43,6 +43,7 @@ const additionalVisitorKeys = {
|
||||
AsExpression: ["expression", "typeAnnotation"],
|
||||
AsConstExpression: ["expression"],
|
||||
SatisfiesExpression: ["expression", "typeAnnotation"],
|
||||
TypeofTypeAnnotation: ["argument", "typeArguments"],
|
||||
};
|
||||
|
||||
const excludeKeys = {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`typeof-with-type-arguments.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
type Foo = typeof MyGenericClass<string, number>;
|
||||
|
||||
=====================================output=====================================
|
||||
type Foo = typeof MyGenericClass<string, number>;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1 @@
|
||||
run_spec(import.meta, ["flow"]);
|
||||
@@ -0,0 +1 @@
|
||||
type Foo = typeof MyGenericClass<string, number>;
|
||||
@@ -1043,6 +1043,7 @@ exports[`visitor keys estree 1`] = `
|
||||
],
|
||||
"TypeofTypeAnnotation": [
|
||||
"argument",
|
||||
"typeArguments",
|
||||
],
|
||||
"UnaryExpression": [
|
||||
"argument",
|
||||
|
||||
Reference in new issue
Block a user