Skip to content

Commit b0dbf85

Browse files
authored
refactor: unvendor typescript types definitions (#234)
Removed the vendored typescript definitions for the old versions in favor of installing it from the package manager (`typescript-3` and `typescript-4.7`). This should result in less code to maintain and (hopefully) more accurate types
1 parent 6b228e5 commit b0dbf85

File tree

7 files changed

+36
-32884
lines changed

7 files changed

+36
-32884
lines changed

.prettierignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
src/declarations/*
21
CHANGELOG.md

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
"@types/node": "^18.19.43",
6262
"@types/ts-expose-internals": "npm:ts-expose-internals@4.9.5",
6363
"@types/ts-node": "npm:ts-node@^10.9.2",
64+
"@types/typescript-3": "npm:typescript@3.x",
65+
"@types/typescript-4.7": "npm:typescript@4.7.x",
6466
"changelogen": "^0.5.5",
6567
"eslint": "9.x",
6668
"globals": "^15.9.0",

src/declarations/typescript3.d.ts

-13,717
This file was deleted.

src/declarations/typescript4.7.d.ts

-19,157
This file was deleted.

src/harmony/versions/four-seven.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* Changes after this point: https://github.com/microsoft/TypeScript/wiki/API-Breaking-Changes#typescript-48
33
*/
4-
import TsCurrentModule, {
4+
import type {
5+
default as TsCurrentModule,
56
AssertClause,
67
ExportDeclaration,
78
Expression,
@@ -13,9 +14,9 @@ import TsCurrentModule, {
1314
ModuleName,
1415
NamedExportBindings,
1516
} from "typescript";
16-
import TsFourSevenModule from "../../declarations/typescript4.7";
17-
import { TsTransformPathsContext } from "../../types";
18-
import { DownSampleTsTypes } from "../utils";
17+
import type TsFourSevenModule from "typescript-4.7";
18+
import type { TsTransformPathsContext } from "../../types";
19+
import type { DownSampleTsTypes } from "../utils";
1920

2021
/* ****************************************************************************************************************** */
2122
// region: Mapping

src/harmony/versions/three-eight.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* Changes after this point: https://github.com/microsoft/TypeScript/wiki/API-Breaking-Changes#typescript-40
33
*/
4-
import TsCurrentModule, {
4+
import type {
5+
default as TsCurrentModule,
56
EntityName,
67
ExportDeclaration,
78
Expression,
@@ -18,9 +19,9 @@ import TsCurrentModule, {
1819
NamedImportBindings,
1920
TypeNode,
2021
} from "typescript";
21-
import type TsThreeEightModule from "../../declarations/typescript3";
22-
import { TsTransformPathsContext } from "../../types";
23-
import { DownSampleTsTypes } from "../utils";
22+
import type TsThreeEightModule from "typescript-3";
23+
import type { TsTransformPathsContext } from "../../types";
24+
import type { DownSampleTsTypes } from "../utils";
2425

2526
/* ****************************************************************************************************************** */
2627
// region: Mapping
@@ -30,6 +31,7 @@ export type TypeMap = [
3031
[TsCurrentModule.SourceFile, TsThreeEightModule.SourceFile],
3132
[TsCurrentModule.StringLiteral, TsThreeEightModule.StringLiteral],
3233
[TsCurrentModule.CompilerOptions, TsThreeEightModule.CompilerOptions],
34+
// @ts-expect-error typescript 3 doesn't export EmitResolver
3335
[TsCurrentModule.EmitResolver, TsThreeEightModule.EmitResolver],
3436
[TsCurrentModule.CallExpression, TsThreeEightModule.CallExpression],
3537
[TsCurrentModule.ExternalModuleReference, TsThreeEightModule.ExternalModuleReference],
@@ -74,6 +76,7 @@ export function handler(context: TsTransformPathsContext, prop: string | symbol)
7476
name: Identifier | undefined,
7577
namedBindings: NamedImportBindings | undefined,
7678
) {
79+
// @ts-expect-error TODO investigate type issue
7780
return ts.updateImportClause.apply(void 0, downSample(node, name, namedBindings));
7881
};
7982
case "updateImportDeclaration":
@@ -108,7 +111,6 @@ export function handler(context: TsTransformPathsContext, prop: string | symbol)
108111
dsNode.modifiers,
109112
dsExportClause,
110113
dsModuleSpecifier,
111-
// @ts-expect-error - This was added in later versions of 3.x
112114
dsNode.isTypeOnly,
113115
);
114116
};

yarn.lock

+22
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,26 @@ __metadata:
302302
languageName: node
303303
linkType: hard
304304

305+
"@types/typescript-3@npm:typescript@3.x":
306+
version: 3.9.10
307+
resolution: "typescript@npm:3.9.10"
308+
bin:
309+
tsc: bin/tsc
310+
tsserver: bin/tsserver
311+
checksum: 10c0/863cc06070fa18a0f9c6a83265fb4922a8b51bf6f2c6760fb0b73865305ce617ea4bc6477381f9f4b7c3a8cb4a455b054f5469e6e41307733fe6a2bd9aae82f8
312+
languageName: node
313+
linkType: hard
314+
315+
"@types/typescript-4.7@npm:typescript@4.7.x":
316+
version: 4.7.4
317+
resolution: "typescript@npm:4.7.4"
318+
bin:
319+
tsc: bin/tsc
320+
tsserver: bin/tsserver
321+
checksum: 10c0/8c1c4007b6ce5b24c49f0e89173ab9e82687cc6ae54418d1140bb63b82d6598d085ac0f993fe3d3d1fbf87a2c76f1f81d394dc76315bc72c7a9f8561c5d8d205
322+
languageName: node
323+
linkType: hard
324+
305325
"@typescript-eslint/eslint-plugin@npm:8.0.1":
306326
version: 8.0.1
307327
resolution: "@typescript-eslint/eslint-plugin@npm:8.0.1"
@@ -2634,6 +2654,8 @@ __metadata:
26342654
"@types/node": "npm:^18.19.43"
26352655
"@types/ts-expose-internals": "npm:ts-expose-internals@4.9.5"
26362656
"@types/ts-node": "npm:ts-node@^10.9.2"
2657+
"@types/typescript-3": "npm:typescript@3.x"
2658+
"@types/typescript-4.7": "npm:typescript@4.7.x"
26372659
changelogen: "npm:^0.5.5"
26382660
eslint: "npm:9.x"
26392661
globals: "npm:^15.9.0"

0 commit comments

Comments
 (0)