@checkdigit/typescript-config 3.2.0 → 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/README.md +1 -1
- package/package.json +1 -41
- package/src/index.ts +135 -0
- package/tsconfig.json +2 -2
package/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://github.com/checkdigit/typescript-config/blob/master/LICENSE.txt)
|
4
4
|
|
5
|
-
Copyright (c) 2022 [Check Digit, LLC](https://checkdigit.com)
|
5
|
+
Copyright (c) 2022-2023 [Check Digit, LLC](https://checkdigit.com)
|
6
6
|
|
7
7
|
### Introduction
|
8
8
|
|
package/package.json
CHANGED
@@ -1,41 +1 @@
|
|
1
|
-
{
|
2
|
-
"name": "@checkdigit/typescript-config",
|
3
|
-
"version": "3.2.0",
|
4
|
-
"description": "Check Digit standard Typescript configuration",
|
5
|
-
"prettier": "@checkdigit/prettier-config",
|
6
|
-
"engines": {
|
7
|
-
"node": ">=16"
|
8
|
-
},
|
9
|
-
"peerDependencies": {
|
10
|
-
"@types/node": ">=16",
|
11
|
-
"typescript": ">=4.9.3 <5.0"
|
12
|
-
},
|
13
|
-
"repository": {
|
14
|
-
"type": "git",
|
15
|
-
"url": "git+https://github.com/checkdigit/typescript-config.git"
|
16
|
-
},
|
17
|
-
"author": "Check Digit, LLC",
|
18
|
-
"license": "MIT",
|
19
|
-
"bugs": {
|
20
|
-
"url": "https://github.com/checkdigit/typescript-config/issues"
|
21
|
-
},
|
22
|
-
"homepage": "https://github.com/checkdigit/typescript-config#readme",
|
23
|
-
"scripts": {
|
24
|
-
"preversion": "npm test",
|
25
|
-
"postversion": "git push && git push --tags",
|
26
|
-
"prettier": "prettier --list-different .",
|
27
|
-
"prettier:fix": "prettier --write .",
|
28
|
-
"test": "npm run ci:compile && npm run ci:test && npm run ci:style",
|
29
|
-
"ci:compile": "tsc --noEmit",
|
30
|
-
"ci:test": "tsc && node build/index.js | grep -q 'complete' && rimraf build",
|
31
|
-
"ci:style": "npm run prettier"
|
32
|
-
},
|
33
|
-
"devDependencies": {
|
34
|
-
"@checkdigit/prettier-config": "^3.1.0",
|
35
|
-
"rimraf": "^3.0.2"
|
36
|
-
},
|
37
|
-
"files": [
|
38
|
-
"tsconfig.json",
|
39
|
-
"SECURITY.md"
|
40
|
-
]
|
41
|
-
}
|
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
@@ -4,6 +4,7 @@
|
|
4
4
|
"target": "es2022",
|
5
5
|
"lib": ["esnext", "dom", "webworker"],
|
6
6
|
"sourceMap": true,
|
7
|
+
"inlineSources": true,
|
7
8
|
"outDir": "build",
|
8
9
|
"declaration": true,
|
9
10
|
"removeComments": false,
|
@@ -17,13 +18,12 @@
|
|
17
18
|
"noUnusedLocals": true,
|
18
19
|
"noUnusedParameters": true,
|
19
20
|
"alwaysStrict": true,
|
20
|
-
"
|
21
|
+
"verbatimModuleSyntax": false,
|
21
22
|
"noFallthroughCasesInSwitch": true,
|
22
23
|
"forceConsistentCasingInFileNames": true,
|
23
24
|
"emitDecoratorMetadata": true,
|
24
25
|
"experimentalDecorators": true,
|
25
26
|
"resolveJsonModule": true,
|
26
|
-
"esModuleInterop": true,
|
27
27
|
"noUncheckedIndexedAccess": true,
|
28
28
|
"noPropertyAccessFromIndexSignature": true,
|
29
29
|
"allowUnusedLabels": false,
|