Skip to content

Commit 9101ee5

Browse files
authored
breaking: require TS 4.5 at least (#817)
* TS minimal requirement v4.5 * wip: test old ts * remove downlevel-dts * simplify test * simplify test 2 * simplify test 3 * wip: useMaybePromise * wip: useMaybePromise 2 * wip: useMaybePromise 3 * rename back
1 parent e91b0cb commit 9101ee5

6 files changed

Lines changed: 26 additions & 61 deletions

File tree

.github/workflows/test-old-typescript.yml

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,14 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
typescript:
16+
- 5.2.2
1617
- 5.1.6
1718
- 5.0.4
1819
- 4.9.5
1920
- 4.8.4
2021
- 4.7.4
2122
- 4.6.4
2223
- 4.5.5
23-
- 4.4.4
24-
- 4.3.5
25-
- 4.2.3
26-
- 4.1.5
27-
- 4.0.5
28-
- 3.9.7
29-
- 3.8.3
30-
- 3.7.5
3124
steps:
3225
- uses: actions/checkout@v2
3326
- uses: actions/setup-node@v2
@@ -40,35 +33,14 @@ jobs:
4033
- name: Patch for Old TS
4134
run: |
4235
sed -i~ 's/\/\/ @ts-expect-error.*\[LATEST-TS-ONLY\]//' tests/*.tsx
43-
sed -i~ 's/"target":/"skipLibCheck":true,"target":/' tsconfig.json
44-
sed -i~ 's/"exactOptionalPropertyTypes": true,//' tsconfig.json
4536
sed -i~ 's/"moduleResolution": "bundler",/"moduleResolution": "node",/' tsconfig.json
4637
sed -i~ 's/"allowImportingTsExtensions": true,//' tsconfig.json
47-
sed -i~ 's/"valtio": \["\.\/src\/index\.ts"\],/"valtio": [".\/dist\/ts3.4\/index.d.ts"],/' tsconfig.json
48-
sed -i~ 's/"valtio\/\*": \["\.\/src\/\*\.ts"\]/"valtio\/*": [".\/dist\/ts3.4\/*.d.ts"]/' tsconfig.json
38+
sed -i~ 's/"valtio": \["\.\/src\/index\.ts"\],/"valtio": [".\/dist\/index.d.ts"],/' tsconfig.json
39+
sed -i~ 's/"valtio\/\*": \["\.\/src\/\*\.ts"\]/"valtio\/*": [".\/dist\/*.d.ts"]/' tsconfig.json
4940
sed -i~ 's/"include": .*/"include": ["src\/types.d.ts", "dist\/**\/*", "tests\/**\/*"],/' tsconfig.json
50-
- name: Patch for Older TS
51-
if: ${{ matrix.typescript == '4.2.3' || matrix.typescript == '4.1.5' || matrix.typescript == '4.0.5' || startsWith(matrix.typescript, '3.') }}
52-
run: |
53-
sed -i~ 's/import\.meta\.env/(import.meta.env as any)/' tests/*.tsx
54-
sed -i~ '1s/^/import React from "react";/' tests/*.tsx
55-
sed -i~ 's/"jsx": "react-jsx"/"jsx": "react"/' tsconfig.json
56-
sed -i~ 's/"noUncheckedIndexedAccess": true,//' tsconfig.json
57-
yarn json -I -f package.json -e "this.resolutions={}; this.resolutions['pretty-format']='25.5.0'; this.resolutions['@types/prettier']='2.4.2'; this.resolutions['@types/yargs']='17.0.13'; this.resolutions['@types/node']='18.11.18';"
58-
59-
rm -r tests/macro-vite.*
6041
- name: Install old TypeScript
6142
run: |
6243
yarn add -D typescript@${{ matrix.typescript }}
63-
rm node_modules/parse5/dist/*.d.ts
64-
- name: Patch testing setup for older TS
65-
if: ${{ matrix.typescript == '4.0.5' || startsWith(matrix.typescript, '3.') }}
66-
run: |
67-
yarn add -D @testing-library/[email protected] @testing-library/[email protected]
68-
rm node_modules/vitest/dist/*.d.ts
69-
rm node_modules/parse5/dist/*.d.ts
70-
echo "declare module 'vitest'" >> ./src/types.d.ts
7144
- name: Test ${{ matrix.typescript }}
7245
run: |
73-
rm -r node_modules/@types/babel__core/node_modules
7446
yarn tsc --noEmit

package.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@
99
"main": "./index.js",
1010
"types": "./index.d.ts",
1111
"typesVersions": {
12-
"<4.5": {
12+
">=4.5": {
1313
"esm/*": [
14-
"ts3.4/*"
14+
"esm/*"
1515
],
1616
"*": [
17-
"ts3.4/*"
17+
"*"
18+
]
19+
},
20+
"*": {
21+
"esm/*": [
22+
"ts_version_4.5_and_above_is_required.d.ts"
23+
],
24+
"*": [
25+
"ts_version_4.5_and_above_is_required.d.ts"
1826
]
1927
}
2028
},
@@ -65,7 +73,7 @@
6573
"build:react_utils": "rollup -c --config-react_utils",
6674
"build:macro": "rollup -c --config-macro",
6775
"build:macro_vite": "rollup -c --config-macro_vite",
68-
"postbuild": "yarn patch-d-ts && yarn copy && yarn patch-macro-vite && yarn patch-ts3.4 && yarn patch-esm-ts",
76+
"postbuild": "yarn patch-d-ts && yarn copy && yarn patch-macro-vite && yarn patch-old-ts && yarn patch-esm-ts",
6977
"prettier": "prettier '*.{js,json,md}' '{src,tests,docs}/**/*.{ts,tsx,md,mdx}' --write",
7078
"prettier:ci": "prettier '*.{js,json,md}' '{src,tests,docs}/**/*.{ts,tsx,md,mdx}' --list-different",
7179
"eslint": "eslint --no-eslintrc --c .eslintrc.json --fix '*.{js,json,ts}' '{src,tests}/**/*.{ts,tsx}'",
@@ -74,9 +82,9 @@
7482
"test": "vitest --ui --coverage",
7583
"test:ci": "vitest",
7684
"patch-d-ts": "node -e \"var {entries}=require('./rollup.config.js');require('shelljs').find('dist/**/*.d.ts').forEach(f=>{entries.forEach(({find,replacement})=>require('shelljs').sed('-i',new RegExp(' from \\''+find.source.slice(0,-1)+'\\';$'),' from \\''+replacement+'\\';',f));require('shelljs').sed('-i',/ from '(\\.[^']+)\\.ts';$/,' from \\'\\$1\\';',f)})\"",
77-
"copy": "shx cp -r dist/src/* dist/esm && shx cp -r dist/src/* dist && shx rm -rf dist/{src,tests} && downlevel-dts dist dist/ts3.4 && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined;\"",
78-
"patch-macro-vite": "shx cp dist/esm/macro/vite.d.ts dist/macro/ && shx cp dist/ts3.4/esm/macro/vite.d.ts dist/ts3.4/macro/",
79-
"patch-ts3.4": "node -e \"require('shelljs').find('dist/ts3.4/**/*.d.ts').forEach(f=>{require('fs').appendFileSync(f,'declare type Awaited<T> = T extends Promise<infer V> ? V : T;');require('shelljs').sed('-i',/^declare type Snapshot<T> =/,'declare type Snapshot<T> = T extends SnapshotIgnore ? T : T extends Promise<unknown> ? Awaited<T> : T extends object ? { readonly [K in keyof T]: Snapshot2<T[K]> } : T; declare type Snapshot2<T> = T extends SnapshotIgnore ? T : T extends Promise<unknown> ? Awaited<T> : T extends object ? { readonly [K in keyof T]: T[K] } : T;;declare type _Snapshot<T> =',f)})\"",
85+
"copy": "shx cp -r dist/src/* dist/esm && shx cp -r dist/src/* dist && shx rm -rf dist/{src,tests} && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined;\"",
86+
"patch-macro-vite": "shx cp dist/esm/macro/vite.d.ts dist/macro/",
87+
"patch-old-ts": "shx touch dist/ts_version_4.5_and_above_is_required.d.ts",
8088
"patch-esm-ts": "node -e \"require('shelljs').find('dist/esm/**/*.d.ts').forEach(f=>{var f2=f.replace(/\\.ts$/,'.mts');require('fs').copyFileSync(f,f2);require('shelljs').sed('-i',/ from '(\\.[^']+)';$/,' from \\'\\$1.mjs\\';',f2);require('shelljs').sed('-i',/^declare module '(\\.[^']+)'/,'declare module \\'\\$1.mjs\\'',f2)})\""
8189
},
8290
"engines": {
@@ -143,7 +151,6 @@
143151
"babel-plugin-macros": "^3.1.0",
144152
"babel-plugin-tester": "10.1.0",
145153
"concurrently": "^8.2.2",
146-
"downlevel-dts": "^0.11.0",
147154
"esbuild": "^0.19.5",
148155
"eslint": "^8.52.0",
149156
"eslint-config-prettier": "^9.0.0",

tests/async.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const sleep = (ms: number) =>
1010
setTimeout(resolve, ms)
1111
})
1212

13-
const { use } = ReactExports as any // for TS < 4.3 FIXME later
14-
const use2 = (x: any) => (x instanceof Promise ? use(x) : x)
13+
const { use } = ReactExports
14+
const use2 = <T,>(x: T): Awaited<T> => (x instanceof Promise ? use(x) : x)
1515

1616
it.skipIf(typeof use === 'undefined')('delayed increment', async () => {
1717
const state = proxy<any>({ count: 0 })

tests/computed.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
77
import { proxy, snapshot, subscribe, useSnapshot } from 'valtio'
88
import { addComputed, proxyWithComputed, subscribeKey } from 'valtio/utils'
99

10-
const { use } = ReactExports as any // for TS < 4.3 FIXME later
11-
const use2 = (x: any) => (x instanceof Promise ? use(x) : x)
10+
const { use } = ReactExports
11+
const use2 = <T,>(x: T): Awaited<T> => (x instanceof Promise ? use(x) : x)
1212

1313
const consoleWarn = console.warn
1414
beforeEach(() => {

tests/derive.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const sleep = (ms: number) =>
1313
setTimeout(resolve, ms)
1414
})
1515

16-
const { use } = ReactExports as any // for TS < 4.3 FIXME later
17-
const use2 = (x: any) => (x instanceof Promise ? use(x) : x)
16+
const { use } = ReactExports
17+
const use2 = <T,>(x: T): Awaited<T> => (x instanceof Promise ? use(x) : x)
1818

1919
it('basic derive', async () => {
2020
const computeDouble = vi.fn((x: number) => x * 2)

yarn.lock

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,15 +2508,6 @@ domexception@^4.0.0:
25082508
dependencies:
25092509
webidl-conversions "^7.0.0"
25102510

2511-
downlevel-dts@^0.11.0:
2512-
version "0.11.0"
2513-
resolved "https://registry.yarnpkg.com/downlevel-dts/-/downlevel-dts-0.11.0.tgz#514a2d723009c5845730c1db6c994484c596ed9c"
2514-
integrity sha512-vo835pntK7kzYStk7xUHDifiYJvXxVhUapt85uk2AI94gUUAQX9HNRtrcMHNSc3YHJUEHGbYIGsM99uIbgAtxw==
2515-
dependencies:
2516-
semver "^7.3.2"
2517-
shelljs "^0.8.3"
2518-
typescript next
2519-
25202511
electron-to-chromium@^1.4.535:
25212512
version "1.4.575"
25222513
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.575.tgz#7c0b87eb2c6214a993699792abd704de41255c39"
@@ -4534,7 +4525,7 @@ semver@^6.3.1:
45344525
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
45354526
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==
45364527

4537-
semver@^7.3.2, semver@^7.5.3, semver@^7.5.4:
4528+
semver@^7.5.3, semver@^7.5.4:
45384529
version "7.5.4"
45394530
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
45404531
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
@@ -4584,7 +4575,7 @@ shell-quote@^1.8.1:
45844575
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.8.1.tgz#6dbf4db75515ad5bac63b4f1894c3a154c766680"
45854576
integrity sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==
45864577

4587-
shelljs@^0.8.3, shelljs@^0.8.5:
4578+
shelljs@^0.8.5:
45884579
version "0.8.5"
45894580
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.5.tgz#de055408d8361bed66c669d2f000538ced8ee20c"
45904581
integrity sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==
@@ -4984,11 +4975,6 @@ typescript@^5.2.2:
49844975
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78"
49854976
integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==
49864977

4987-
typescript@next:
4988-
version "5.3.0-dev.20231102"
4989-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.0-dev.20231102.tgz#2baa0540e57ce8a4fbf283b17c194b6ea2ffc412"
4990-
integrity sha512-M1maLdHyAvE+y4w27IBplkqekR5Lzf2B7XualvF3lXJUC2165swvSmpThFdfHcXxP/+/SYmLI9z2CVvN7pEK+g==
4991-
49924978
ufo@^1.3.0:
49934979
version "1.3.1"
49944980
resolved "https://registry.yarnpkg.com/ufo/-/ufo-1.3.1.tgz#e085842f4627c41d4c1b60ebea1f75cdab4ce86b"

0 commit comments

Comments
 (0)