diff --git a/baselines/ts3.4/src/test.d.ts b/baselines/ts3.4/src/test.d.ts index 62a03dd..a14ae01 100644 --- a/baselines/ts3.4/src/test.d.ts +++ b/baselines/ts3.4/src/test.d.ts @@ -17,3 +17,5 @@ export interface E { b: number; } export type F = Omit; +export declare let readonlyArr: ReadonlyArray; +export declare let readonlyTuple: Readonly<[string, number]>; diff --git a/index.js b/index.js index ffedd05..6d63dfd 100644 --- a/index.js +++ b/index.js @@ -141,6 +141,18 @@ function doTransform(checker, k) { ]) ]); } + } else if (ts.isTypeOperatorNode(n) && n.operator === ts.SyntaxKind.ReadonlyKeyword) { + if (ts.isArrayTypeNode(n.type)) { + // let arr: readonly number[]; + // => + // let arr: ReadonlyArray; + return ts.createTypeReferenceNode('ReadonlyArray', [transform(n.type.elementType)]); + } else if (ts.isTupleTypeNode(n.type)) { + // let tup: readonly [string, number]; + // => + // let tup: Readonly<[string, number]>; + return ts.createTypeReferenceNode('Readonly', [transform(n.type)]); + } } return ts.visitEachChild(n, transform, k); }; diff --git a/test/src/test.d.ts b/test/src/test.d.ts index efc39b4..9f4a9d8 100644 --- a/test/src/test.d.ts +++ b/test/src/test.d.ts @@ -22,4 +22,7 @@ export interface E { b: number; } -export type F = Omit; \ No newline at end of file +export type F = Omit; + +export declare let readonlyArr: readonly string[]; +export declare let readonlyTuple: readonly [string, number];