From 205a2e83ace4af595ae7deb071119c95fbb6dfa3 Mon Sep 17 00:00:00 2001 From: Manuel Serret Date: Tue, 31 Dec 2024 10:15:30 +0100 Subject: [PATCH] feat: support indexed access type --- src/handlers.js | 6 ++++++ test/samples/ts-index-access-type/expected.ts | 4 ++++ test/samples/ts-index-access-type/expected.ts.map | 11 +++++++++++ test/samples/ts-index-access-type/input.ts | 4 ++++ 4 files changed, 25 insertions(+) create mode 100644 test/samples/ts-index-access-type/expected.ts create mode 100644 test/samples/ts-index-access-type/expected.ts.map create mode 100644 test/samples/ts-index-access-type/input.ts diff --git a/src/handlers.js b/src/handlers.js index 66305bf..648db6f 100644 --- a/src/handlers.js +++ b/src/handlers.js @@ -556,6 +556,12 @@ function handle_type_annotation(node, state) { state.commands.push(' : '); handle_type_annotation(node.falseType, state); break; + case 'TSIndexedAccessType': + handle_type_annotation(node.objectType, state); + state.commands.push('['); + handle_type_annotation(node.indexType, state); + state.commands.push(']'); + break; default: throw new Error(`Not implemented type annotation ${node.type}`); } diff --git a/test/samples/ts-index-access-type/expected.ts b/test/samples/ts-index-access-type/expected.ts new file mode 100644 index 0000000..b7e5b35 --- /dev/null +++ b/test/samples/ts-index-access-type/expected.ts @@ -0,0 +1,4 @@ +type A = { a: string; b: number }; +type B = A['b']; + +const c: A['b'] = 1; \ No newline at end of file diff --git a/test/samples/ts-index-access-type/expected.ts.map b/test/samples/ts-index-access-type/expected.ts.map new file mode 100644 index 0000000..d04c1e6 --- /dev/null +++ b/test/samples/ts-index-access-type/expected.ts.map @@ -0,0 +1,11 @@ +{ + "version": 3, + "names": [], + "sources": [ + "input.js" + ], + "sourcesContent": [ + "type A = { a: string; b: number };\ntype B = A['b'];\n\nconst c: A['b'] = 1;\n" + ], + "mappings": "KAAK,CAAC,KAAK,CAAC,UAAU,CAAC;KAClB,CAAC,GAAG,CAAC,CAAC,GAAG;;MAER,CAAS,EAAN,CAAC,CAAC,GAAG,IAAI,CAAC" +} \ No newline at end of file diff --git a/test/samples/ts-index-access-type/input.ts b/test/samples/ts-index-access-type/input.ts new file mode 100644 index 0000000..2cdf80c --- /dev/null +++ b/test/samples/ts-index-access-type/input.ts @@ -0,0 +1,4 @@ +type A = { a: string; b: number }; +type B = A['b']; + +const c: A['b'] = 1;