/
index.ts
134 lines (114 loc) · 3.7 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import assert from "assert";
/*
# How to add a new version of Typescript #
For the RC:
1. Add a new version to the end of `TypeScriptVersion` and `supported`.
`supported` now contains the shipped versions, the RC, and the nightly.
2. Update failing tests.
For the release:
1. Move the newly-released version from `supported` to `shipped`.
`supported` now contains the shipped versions and the nightly.
2. Update failing tests.
# How to deprecate an old version on Definitely Typed #
1. Move the old version from `TypeScriptVersion` to `UnsupportedTypeScriptVersion`.
2. Move the old version from `shipped` to `unsupported`.
3. Update failing tests.
Currently, it's possible to release a new version and deprecate an old version
at the same time because of the way release schedule overlaps.
*/
/** Parseable but unsupported TypeScript versions. */
export type UnsupportedTypeScriptVersion =
| "2.0"
| "2.1"
| "2.2"
| "2.3"
| "2.4"
| "2.5"
| "2.6"
| "2.7"
| "2.8"
| "2.9"
| "3.0"
| "3.1"
| "3.2"
| "3.3"
| "3.4"
| "3.5"
| "3.6"
| "3.7"
| "3.8"
| "3.9"
| "4.0"
| "4.1";
/**
* Parseable and supported TypeScript versions.
* Only add to this list if we will support this version on Definitely Typed.
*/
export type TypeScriptVersion = "4.2" | "4.3" | "4.4" | "4.5" | "4.6" | "4.7" | "4.8" | "4.9" | "5.0";
export type AllTypeScriptVersion = UnsupportedTypeScriptVersion | TypeScriptVersion;
export namespace TypeScriptVersion {
/** Add to this list when a version actually ships. */
export const shipped: readonly TypeScriptVersion[] = ["4.2", "4.3", "4.4", "4.5", "4.6", "4.7", "4.8", "4.9"];
/** Add to this list when a version is available as typescript@next */
export const supported: readonly TypeScriptVersion[] = [...shipped, "5.0"];
/** Add to this list when it will no longer be supported on Definitely Typed */
export const unsupported: readonly UnsupportedTypeScriptVersion[] = [
"2.0",
"2.1",
"2.2",
"2.3",
"2.4",
"2.5",
"2.6",
"2.7",
"2.8",
"2.9",
"3.0",
"3.1",
"3.2",
"3.3",
"3.4",
"3.5",
"3.6",
"3.7",
"3.8",
"3.9",
"4.0",
"4.1",
];
export const all: readonly AllTypeScriptVersion[] = [...unsupported, ...supported];
export const lowest = supported[0];
/** Latest version that may be specified in a `// TypeScript Version:` header. */
export const latest = supported[supported.length - 1];
export function isSupported(v: AllTypeScriptVersion): v is TypeScriptVersion {
return supported.indexOf(v as TypeScriptVersion) > -1;
}
export function range(min: TypeScriptVersion): readonly TypeScriptVersion[] {
return supported.filter((v) => v >= min);
}
/** List of NPM tags that should be changed to point to the latest version. */
export function tagsToUpdate(v: TypeScriptVersion): readonly string[] {
const idx = supported.indexOf(v);
assert(idx !== -1);
return supported
.slice(idx)
.map((v) => "ts" + v)
.concat("latest");
}
export function previous(v: TypeScriptVersion): TypeScriptVersion | undefined {
const index = supported.indexOf(v);
assert(index !== -1);
return index === 0 ? undefined : supported[index - 1];
}
export function next(v: TypeScriptVersion): TypeScriptVersion | undefined {
const index = supported.indexOf(v);
assert(index !== -1);
return index === supported.length - 1 ? undefined : supported[index + 1];
}
export function isRedirectable(v: TypeScriptVersion): boolean {
return all.indexOf(v) >= all.indexOf("3.1");
}
export function isTypeScriptVersion(str: string): str is TypeScriptVersion {
return all.includes(str as TypeScriptVersion);
}
}