Skip to content

Commit acb8499

Browse files
✨ Add support for TSUnknown (#112)
1 parent ac7709a commit acb8499

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"releases": [{ "name": "extract-react-types", "type": "minor" }],
3+
"dependents": [
4+
{
5+
"name": "babel-plugin-extract-react-types",
6+
"type": "patch",
7+
"dependencies": ["extract-react-types"]
8+
},
9+
{
10+
"name": "extract-react-types-loader",
11+
"type": "patch",
12+
"dependencies": ["extract-react-types"]
13+
},
14+
{ "name": "kind2string", "type": "patch", "dependencies": ["extract-react-types"] },
15+
{
16+
"name": "pretty-proptypes",
17+
"type": "patch",
18+
"dependencies": ["kind2string", "extract-react-types"]
19+
}
20+
]
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adds support for the TSUnknownKeyword

packages/extract-react-types/__snapshots__/test.js.snap

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4956,6 +4956,37 @@ Object {
49564956
}
49574957
`;
49584958

4959+
exports[`ts unknown prop 1`] = `
4960+
Object {
4961+
"component": Object {
4962+
"kind": "generic",
4963+
"name": Object {
4964+
"kind": "id",
4965+
"name": "Component",
4966+
"type": null,
4967+
},
4968+
"value": Object {
4969+
"kind": "object",
4970+
"members": Array [
4971+
Object {
4972+
"key": Object {
4973+
"kind": "id",
4974+
"name": "children",
4975+
},
4976+
"kind": "property",
4977+
"optional": false,
4978+
"value": Object {
4979+
"kind": "unknown",
4980+
},
4981+
},
4982+
],
4983+
"referenceIdName": "Props",
4984+
},
4985+
},
4986+
"kind": "program",
4987+
}
4988+
`;
4989+
49594990
exports[`ts void 1`] = `
49604991
Object {
49614992
"component": Object {

packages/extract-react-types/src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,11 @@ converters.TSNullKeyword = (path, context): K.Null => {
11931193
return { kind: 'null' };
11941194
};
11951195

1196+
/* eslint-disable-next-line no-unused-vars */
1197+
converters.TSUnknownKeyword = (path, context): K.Unknown => {
1198+
return { kind: 'unknown' };
1199+
};
1200+
11961201
/* eslint-disable-next-line no-unused-vars */
11971202
converters.TSThisType = (path, context): K.This => {
11981203
return { kind: 'custom', value: 'this' };

packages/extract-react-types/src/kinds.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export type Number = {
104104
value?: number
105105
};
106106
export type Null = { kind: 'null' };
107+
export type Unknown = { kind: 'unknown' };
107108
export type TemplateElement = {
108109
kind: 'templateElement',
109110
value: { raw: string, cooked: string }

packages/extract-react-types/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,20 @@ const TESTS = [
16651665
class Component extends React.Component<Foo<string, {}>> {
16661666
}
16671667
`
1668+
},
1669+
{
1670+
name: 'ts unknown prop',
1671+
typeSystem: 'typescript',
1672+
code: `
1673+
import React from 'react';
1674+
1675+
type Props = {
1676+
children: unknown,
1677+
};
1678+
1679+
class Component extends React.Component<Props> {
1680+
}
1681+
`
16681682
}
16691683
];
16701684

0 commit comments

Comments
 (0)