Skip to content
This repository was archived by the owner on Jan 9, 2021. It is now read-only.

Commit 5547646

Browse files
committed
initial implementation
1 parent 07c0f14 commit 5547646

14 files changed

+1608
-1
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
trim_trailing_whitespace = true
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 4
8+
indent_style = space
9+
insert_final_newline = true
10+
11+
[*.{json,yaml,yml,md}]
12+
indent_size = 2

.gitignore

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# TypeScript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# next.js build output
61+
.next
62+
63+
# TypeScript compiler output
64+
/dist
65+
66+
# test output
67+
/test/out

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: node_js
2+
node_js:
3+
- '6'
4+
- '8'
5+
- '10'
6+
- '11'
7+
cache: yarn
8+
script:
9+
- yarn verify

.wotanrc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extends: wotan:recommended

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
11
# ts-transform-readonly-array
2-
Convert 'readonly T[]' to 'ReadonlyArray<T>' in declaration emit
2+
3+
TypeScript transformer to convert `readonly T[]` to `ReadonlyArray<T>` in declaration files.
4+
5+
## Why
6+
7+
Starting from v3.4.0 (or one of the nightly releases before that) TypeScript emits `readonly T[]` for readonly array types.
8+
This breaks consumers of declaration files if they use an older version of TypeScript.
9+
10+
This transformer ensures that your declaration files can be used in older TypeScript versions as well.
11+
12+
It does not convert readonly tuple types in the form of `readonly [string, number]` as this is not supported in older versions of TypeScript.
13+
14+
## Usage with `ttypescript`
15+
16+
I wrote this transformer for use with [`ttypescript`](https://github.com/cevek/ttypescript).
17+
18+
You can configure it in your `tsconfig.json`:
19+
20+
```js
21+
{
22+
"compilerOptions": {
23+
"declaration": true,
24+
"plugins": [
25+
{ "transform": "ts-transform-readonly-array", "afterDeclarations": true },
26+
]
27+
}
28+
}
29+
```
30+
31+
Note that you can use any `"type"` for the transformer: the default is `"type": "program"`, but it also works with `"type": "raw"` for example.
32+
33+
Afterwards you run `ttsc` as you would run `tsc`.
34+
35+
## Usage with `ts-loader`, `rollup`, and TypeScript's API
36+
37+
This package exports the necessary factory function to create the transformer. You can use this function to plug this transformer in any major TypeScript compilation pipeline.
38+
Please refer to the API documentation of the tool you are using. Alternatively you can use [`ttypescript`](https://github.com/cevek/ttypescript) in most tools.

0 commit comments

Comments
 (0)