Skip to content

Commit d232e30

Browse files
soswowNoviny
authored andcommitted
Implement quick TSConditionalType stub solution (#76)
* Implement quick TSConditionalType stub solution * Changeset
1 parent 98e8a63 commit d232e30

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

.changeset/7e14e139/changes.json

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": "pretty-proptypes",
11+
"type": "patch",
12+
"dependencies": ["kind2string", "extract-react-types"]
13+
},
14+
{
15+
"name": "extract-react-types-loader",
16+
"type": "patch",
17+
"dependencies": ["extract-react-types"]
18+
},
19+
{ "name": "kind2string", "type": "patch", "dependencies": ["extract-react-types"] }
20+
]
21+
}

.changeset/7e14e139/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement stub for TSConditionalType

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3955,6 +3955,39 @@ Object {
39553955
}
39563956
`;
39573957

3958+
exports[`ts custom prop 2`] = `
3959+
Object {
3960+
"component": Object {
3961+
"key": Object {
3962+
"kind": "any",
3963+
},
3964+
"kind": "generic",
3965+
"name": Object {
3966+
"kind": "id",
3967+
"name": "Component",
3968+
"type": null,
3969+
},
3970+
"typeParams": Object {
3971+
"kind": "typeParams",
3972+
"params": Array [
3973+
Object {
3974+
"kind": "string",
3975+
},
3976+
Object {
3977+
"kind": "object",
3978+
"members": Array [],
3979+
},
3980+
],
3981+
},
3982+
"value": Object {
3983+
"kind": "any",
3984+
"referenceIdName": "Foo",
3985+
},
3986+
},
3987+
"kind": "program",
3988+
}
3989+
`;
3990+
39583991
exports[`ts decorators 1`] = `
39593992
Object {
39603993
"component": Object {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,12 @@ converters.ImportSpecifier = (path, context): K.Import => {
13961396
return importConverterGeneral(path, context);
13971397
};
13981398

1399+
converters.TSConditionalType = (): K.Any => {
1400+
return {
1401+
kind: 'any'
1402+
};
1403+
};
1404+
13991405
function convertMethodCall(path, context): K.Func {
14001406
const parameters = path.get('parameters').map(p => convertParameter(p, context));
14011407
const returnType = convert(path.get('typeAnnotation'), context);

packages/extract-react-types/test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,17 @@ const TESTS = [
16091609
}
16101610
}
16111611
`
1612-
}
1612+
},
1613+
{
1614+
name: 'ts custom prop',
1615+
typeSystem: 'typescript',
1616+
code: `
1617+
type Foo<T, U> = T extends object ? T : U;
1618+
1619+
class Component extends React.Component<Foo<string, {}>> {
1620+
}
1621+
`
1622+
},
16131623
];
16141624

16151625
cases(

0 commit comments

Comments
 (0)