Replace ts-node with tsimp (#208)

This commit is contained in:
Bjorn Stromberg 2024-06-25 08:08:48 +08:00 committed by GitHub
parent 47f49741ea
commit 92699e1049
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 21 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
node_modules node_modules
yarn.lock yarn.lock
dist dist
.tsimp

View file

@ -19,7 +19,7 @@
}, },
"scripts": { "scripts": {
"build": "del dist && tsc", "build": "del dist && tsc",
"test": "tsc --noEmit && xo && NODE_OPTIONS='--loader=ts-node/esm --no-warnings=ExperimentalWarning' ava", "test": "tsc --noEmit && xo && ava",
"prepare": "npm run build" "prepare": "npm run build"
}, },
"files": [ "files": [
@ -50,24 +50,30 @@
"types" "types"
], ],
"devDependencies": { "devDependencies": {
"@sindresorhus/tsconfig": "^4.0.0", "@sindresorhus/tsconfig": "^5.0.0",
"@types/jsdom": "^21.1.1", "@types/jsdom": "^21.1.7",
"@types/node": "^20.5.0", "@types/node": "^20.14.8",
"@types/zen-observable": "^0.8.3", "@types/zen-observable": "^0.8.3",
"ava": "^5.3.1", "ava": "^6.1.3",
"del-cli": "^5.0.0", "del-cli": "^5.0.0",
"expect-type": "^0.16.0",
"jsdom": "^22.1.0", "jsdom": "^22.1.0",
"rxjs": "^7.8.1", "rxjs": "^7.8.1",
"tempy": "^3.1.0", "tempy": "^3.1.0",
"ts-node": "^10.9.1", "tsimp": "^2.0.11",
"typescript": "^5.1.6", "typescript": "^5.1.6",
"xo": "^0.56.0", "xo": "^0.56.0",
"zen-observable": "^0.10.0", "zen-observable": "^0.10.0"
"expect-type": "^0.16.0"
}, },
"ava": { "ava": {
"environmentVariables": {
"TSIMP_DIAG": "error"
},
"extensions": { "extensions": {
"ts": "module" "ts": "module"
} },
"nodeArguments": [
"--import=tsimp/import"
]
} }
} }

View file

@ -764,13 +764,13 @@ test('is.array', t => {
t.notThrows(() => { t.notThrows(() => {
const x: unknown[] = [1, 2, 3]; const x: unknown[] = [1, 2, 3];
assert.array(x, assert.number); assert.array(x, assert.number);
x[0].toFixed(0); x[0]?.toFixed(0);
}); });
t.notThrows(() => { t.notThrows(() => {
const x: unknown[] = [1, 2, 3]; const x: unknown[] = [1, 2, 3];
if (is.array<number>(x, is.number)) { if (is.array<number>(x, is.number)) {
x[0].toFixed(0); x[0]?.toFixed(0);
} }
}); });
}); });
@ -1174,7 +1174,7 @@ test('is.falsy', t => {
// Checks that `assert.falsy` narrow downs boolean type to `false`. // Checks that `assert.falsy` narrow downs boolean type to `false`.
{ {
const booleans = [false, true]; const booleans = [false, true];
const function_ = (value: false) => value; const function_ = (value?: false) => value;
assert.falsy(booleans[0]); assert.falsy(booleans[0]);
function_(booleans[0]); function_(booleans[0]);
} }
@ -1182,7 +1182,7 @@ test('is.falsy', t => {
// Checks that `assert.falsy` narrow downs number type to `0`. // Checks that `assert.falsy` narrow downs number type to `0`.
{ {
const bits = [0, -0, 1]; const bits = [0, -0, 1];
const function_ = (value: 0) => value; const function_ = (value?: 0) => value;
assert.falsy(bits[0]); assert.falsy(bits[0]);
function_(bits[0]); function_(bits[0]);
assert.falsy(bits[1]); assert.falsy(bits[1]);
@ -1192,7 +1192,7 @@ test('is.falsy', t => {
// Checks that `assert.falsy` narrow downs bigint type to `0n`. // Checks that `assert.falsy` narrow downs bigint type to `0n`.
{ {
const bits = [0n, -0n, 1n]; const bits = [0n, -0n, 1n];
const function_ = (value: 0n) => value; const function_ = (value?: 0n) => value;
assert.falsy(bits[0]); assert.falsy(bits[0]);
function_(bits[0]); function_(bits[0]);
assert.falsy(bits[1]); assert.falsy(bits[1]);
@ -1202,7 +1202,7 @@ test('is.falsy', t => {
// Checks that `assert.falsy` narrow downs string type to empty string. // Checks that `assert.falsy` narrow downs string type to empty string.
{ {
const strings = ['', 'nonEmpty']; const strings = ['', 'nonEmpty'];
const function_ = (value: '') => value; const function_ = (value?: '') => value;
assert.falsy(strings[0]); assert.falsy(strings[0]);
function_(strings[0]); function_(strings[0]);
} }
@ -1219,7 +1219,7 @@ test('is.falsy', t => {
{ {
const maybeNulls = [null, Symbol('🦄')]; const maybeNulls = [null, Symbol('🦄')];
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
const function_ = (value: null) => value; const function_ = (value?: null) => value;
assert.falsy(maybeNulls[0]); assert.falsy(maybeNulls[0]);
function_(maybeNulls[0]); function_(maybeNulls[0]);
} }

View file

@ -6,9 +6,4 @@
"include": [ "include": [
"source" "source"
], ],
"ts-node": {
"transpileOnly": true,
"files": true,
"experimentalResolver": true
}
} }