@checkdigit/typescript-config 3.2.0-PR.23-1083 → 3.3.0-PR.29-5bac
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +1 -1
- package/README.md +2 -3
- package/package.json +1 -1
- package/src/index.ts +135 -0
- package/tsconfig.json +3 -5
- package/src/module-directory/index.ts +0 -3
- package/src/module.ts +0 -9
package/LICENSE.txt
CHANGED
package/README.md
CHANGED
@@ -8,10 +8,9 @@ Copyright (c) 2022-2023 [Check Digit, LLC](https://checkdigit.com)
|
|
8
8
|
|
9
9
|
This module contains the standard Check Digit Typescript configuration.
|
10
10
|
|
11
|
-
- requires Node
|
11
|
+
- requires Node 16 or above
|
12
12
|
- emits ES2022
|
13
|
-
- uses `
|
14
|
-
- uses the `moduleResoltion` of `bundler`
|
13
|
+
- uses the `module` type of `commonjs`.
|
15
14
|
- all compiler options set for maximum strictness
|
16
15
|
|
17
16
|
#### A note about versioning
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"name":"@checkdigit/typescript-config","version":"3.
|
1
|
+
{"name":"@checkdigit/typescript-config","version":"3.3.0-PR.29-5bac","description":"Check Digit standard Typescript configuration","prettier":"@checkdigit/prettier-config","engines":{"node":">=16"},"peerDependencies":{"@types/node":">=16","typescript":">=5.0.2 <5.1"},"repository":{"type":"git","url":"git+https://github.com/checkdigit/typescript-config.git"},"author":"Check Digit, LLC","license":"MIT","bugs":{"url":"https://github.com/checkdigit/typescript-config/issues"},"homepage":"https://github.com/checkdigit/typescript-config#readme","scripts":{"preversion":"npm test","postversion":"git push && git push --tags","prettier":"prettier --list-different .","prettier:fix":"prettier --write .","test":"npm run ci:compile && npm run ci:test && npm run ci:style","ci:compile":"tsc --noEmit","ci:test":"tsc && node build/index.js | grep -q 'complete' && rimraf build","ci:style":"npm run prettier"},"devDependencies":{"@checkdigit/prettier-config":"^3.3.0","rimraf":"^4.4.0"},"files":["tsconfig.json","SECURITY.md","/src/"]}
|
package/src/index.ts
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
// index.ts
|
2
|
+
|
3
|
+
import { strict as assert } from 'node:assert';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Check for Typescript 4.4 features
|
7
|
+
*/
|
8
|
+
|
9
|
+
interface SymbolIndexSignature44 {
|
10
|
+
[name: symbol]: number;
|
11
|
+
}
|
12
|
+
|
13
|
+
assert.ok({} as SymbolIndexSignature44);
|
14
|
+
|
15
|
+
interface Person44 {
|
16
|
+
name: string;
|
17
|
+
age?: number;
|
18
|
+
}
|
19
|
+
|
20
|
+
// @ts-expect-error
|
21
|
+
const person: Person44 = {
|
22
|
+
name: 'Bob',
|
23
|
+
age: undefined, // errors with exactOptionalPropertyTypes = true.
|
24
|
+
};
|
25
|
+
|
26
|
+
try {
|
27
|
+
console.log('hello');
|
28
|
+
} catch (error) {
|
29
|
+
// @ts-expect-error
|
30
|
+
console.error(err.message); // errors with useUnknownInCatchVariables = true
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Check for Typescript 4.5 features
|
35
|
+
*/
|
36
|
+
|
37
|
+
// type modifiers on import names
|
38
|
+
import { ok, type AssertPredicate } from 'node:assert';
|
39
|
+
|
40
|
+
ok({} as AssertPredicate);
|
41
|
+
|
42
|
+
// Awaited type
|
43
|
+
ok({} as Awaited<Promise<string>>);
|
44
|
+
|
45
|
+
// template string types as discriminants
|
46
|
+
interface Success45 {
|
47
|
+
type: `${string}Success`;
|
48
|
+
body: string;
|
49
|
+
}
|
50
|
+
|
51
|
+
interface Error45 {
|
52
|
+
type: `${string}Error`;
|
53
|
+
message: string;
|
54
|
+
}
|
55
|
+
|
56
|
+
function handler45(r: Success45 | Error45) {
|
57
|
+
if (r.type === 'HttpSuccess') {
|
58
|
+
// 'r' has type 'Success'
|
59
|
+
assert.ok(r.body);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
handler45({ type: 'HttpSuccess', body: 'Hello' });
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Check for Typescript 4.6 features
|
66
|
+
*/
|
67
|
+
|
68
|
+
// control flow analysis for destructured discriminated unions
|
69
|
+
type Action46 = { kind: 'NumberContents'; payload: number } | { kind: 'StringContents'; payload: string };
|
70
|
+
|
71
|
+
function processAction46(action: Action46) {
|
72
|
+
const { kind, payload } = action;
|
73
|
+
if (kind === 'NumberContents') {
|
74
|
+
assert.ok(payload * 2);
|
75
|
+
} else if (kind === 'StringContents') {
|
76
|
+
assert.ok(payload.trim());
|
77
|
+
}
|
78
|
+
}
|
79
|
+
assert.equal(processAction46({ kind: 'NumberContents', payload: 5 }), undefined);
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Check for Typescript 4.7 features
|
83
|
+
*/
|
84
|
+
|
85
|
+
// control-flow analysis for bracketed element access
|
86
|
+
const key = Symbol();
|
87
|
+
const numberOrString = Math.random() < 0.5 ? 42 : 'hello';
|
88
|
+
const obj = {
|
89
|
+
[key]: numberOrString,
|
90
|
+
};
|
91
|
+
if (typeof obj[key] === 'string') {
|
92
|
+
assert.ok(obj[key].toUpperCase()); // 4.7 knows that obj[key] is a string
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Check for Typescript 4.8 features
|
97
|
+
*/
|
98
|
+
|
99
|
+
// improved intersection reduction, union compatibility, and narrowing
|
100
|
+
function f48(x: unknown, y: {} | null | undefined) {
|
101
|
+
x = y;
|
102
|
+
y = x; // works in 4.8
|
103
|
+
assert.equal(x, y);
|
104
|
+
}
|
105
|
+
f48(null, undefined);
|
106
|
+
|
107
|
+
function foo48<T>(x: NonNullable<T>, y: NonNullable<NonNullable<T>>) {
|
108
|
+
x = y;
|
109
|
+
y = x; // works in 4.8
|
110
|
+
assert.equal(x, y);
|
111
|
+
}
|
112
|
+
foo48<string>('hello', 'world');
|
113
|
+
|
114
|
+
function throwIfNullable48<T>(value: T): NonNullable<T> {
|
115
|
+
if (value === undefined || value === null) {
|
116
|
+
throw Error('Nullable value!');
|
117
|
+
}
|
118
|
+
return value; // works in 4.8
|
119
|
+
}
|
120
|
+
assert.equal(throwIfNullable48(42), 42);
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Check for Typescript 4.9 features
|
124
|
+
*/
|
125
|
+
type Colors49 = 'red' | 'green' | 'blue';
|
126
|
+
type RGB49 = [red: number, green: number, blue: number];
|
127
|
+
const palette49 = {
|
128
|
+
red: [255, 0, 0],
|
129
|
+
green: '#00ff00',
|
130
|
+
// @ts-expect-error
|
131
|
+
bleu: [0, 0, 255], // typo is now caught
|
132
|
+
} satisfies Record<Colors49, string | RGB49>;
|
133
|
+
assert.equal(typeof palette49, 'object');
|
134
|
+
|
135
|
+
console.log('complete');
|
package/tsconfig.json
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"compilerOptions": {
|
3
|
-
"
|
4
|
-
"
|
5
|
-
"moduleResolution": "bundler",
|
3
|
+
"module": "commonjs",
|
4
|
+
"target": "es2022",
|
6
5
|
"lib": ["esnext", "dom", "webworker"],
|
7
6
|
"sourceMap": true,
|
8
7
|
"inlineSources": true,
|
@@ -19,13 +18,12 @@
|
|
19
18
|
"noUnusedLocals": true,
|
20
19
|
"noUnusedParameters": true,
|
21
20
|
"alwaysStrict": true,
|
22
|
-
"verbatimModuleSyntax":
|
21
|
+
"verbatimModuleSyntax": false,
|
23
22
|
"noFallthroughCasesInSwitch": true,
|
24
23
|
"forceConsistentCasingInFileNames": true,
|
25
24
|
"emitDecoratorMetadata": true,
|
26
25
|
"experimentalDecorators": true,
|
27
26
|
"resolveJsonModule": true,
|
28
|
-
"esModuleInterop": true,
|
29
27
|
"noUncheckedIndexedAccess": true,
|
30
28
|
"noPropertyAccessFromIndexSignature": true,
|
31
29
|
"allowUnusedLabels": false,
|