Skip to content

Commit

Permalink
Merge pull request #18 from manuel3108/feat/support-indexed-access-type
Browse files Browse the repository at this point in the history
feat: support indexed access type
  • Loading branch information
Rich-Harris authored Jan 9, 2025
2 parents a486464 + 205a2e8 commit 5269314
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
4 changes: 4 additions & 0 deletions test/samples/ts-index-access-type/expected.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type A = { a: string; b: number };
type B = A['b'];

const c: A['b'] = 1;
11 changes: 11 additions & 0 deletions test/samples/ts-index-access-type/expected.ts.map
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 4 additions & 0 deletions test/samples/ts-index-access-type/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type A = { a: string; b: number };
type B = A['b'];

const c: A['b'] = 1;

0 comments on commit 5269314

Please sign in to comment.