Skip to content

Commit

Permalink
fix #2798: make type declarations work in TS v3.5+
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jan 7, 2023
1 parent dad3e64 commit b3b06c7
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
run: cd scripts && node gen-unicode-table.js

esbuild-old-golang:
name: esbuild CI (old Go version)
name: esbuild CI (old versions)
runs-on: ubuntu-latest

steps:
Expand All @@ -181,3 +181,6 @@ jobs:

- name: go test
run: go test ./internal/...

- name: make test-old-ts
run: make test-old-ts
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@
export * from "./b"
```

* Remove new type syntax from type declarations in the `esbuild` package ([#2798](https://github.com/evanw/esbuild/issues/2798))

Previously you needed to use TypeScript 4.3 or newer when using the `esbuild` package from TypeScript code due to the use of a getter in an interface in `node_modules/esbuild/lib/main.d.ts`. This release removes this newer syntax to allow people with versions of TypeScript as far back as TypeScript 3.5 to use this latest version of the `esbuild` package. Here is change that was made to esbuild's type declarations:
```diff
export interface OutputFile {
/** "text" as bytes */
contents: Uint8Array;
/** "contents" as text (changes automatically with "contents") */
- get text(): string;
+ readonly text: string;
}
```
## 0.16.14
* Preserve some comments in expressions ([#2721](https://github.com/evanw/esbuild/issues/2721))
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ plugin-tests: version-go
ts-type-tests: | scripts/node_modules
node scripts/ts-type-tests.js

require/old-ts/node_modules:
cd require/old-ts && npm ci

test-old-ts: platform-neutral | require/old-ts/node_modules
rm -fr scripts/.test-old-ts && mkdir scripts/.test-old-ts
cp `find npm/esbuild -name '*.d.ts'` scripts/.test-old-ts
cd scripts/.test-old-ts && ../../require/old-ts/node_modules/.bin/tsc *.d.ts
rm -fr scripts/.test-old-ts

node-unref-tests: | scripts/node_modules
node scripts/node-unref-tests.js

Expand Down
2 changes: 1 addition & 1 deletion lib/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export interface OutputFile {
/** "text" as bytes */
contents: Uint8Array;
/** "contents" as text (changes automatically with "contents") */
get text(): string;
readonly text: string;
}

export interface BuildInvalidate {
Expand Down
3 changes: 3 additions & 0 deletions require/old-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Old TypeScript version

This is used to ensure that our type definitions don't accidentally use newer features that break in older versions of TypeScript.
31 changes: 31 additions & 0 deletions require/old-ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions require/old-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"typescript": "3.5.3"
}
}

0 comments on commit b3b06c7

Please sign in to comment.