fix: recursive T for WritableDraft (#1197)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* chore(__tests__): add vitest globals to tsconfig.json * fix: recursive T for WritableDraft
authored by Homa Wong · committed by GitHub · parent c329ddb · Browse files · 5 files·+67 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+67 added−2 removed
- tests:+21 added−1 removed
- other:+46 added−1 removed
Provenance
- Commit
78ea694- Tree
e2e38e3- Author
Homa Wong <homawong@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
c329ddb
5 files changed+67 added−2 removed
modified:__tests__/tsconfig.json+2 added-1 removed
2 unmodified lines34567789102 unmodified lines "compilerOptions": { "lib": ["es2015"], "strict": true, "noUnusedLocals": false, "target": "ES5" "target": "ES5", "types": ["vitest/globals"] }}added:__tests__/type-external.ts+19 added
12345678910111213141516171819import {isType, JSONArray, JSONObject, JSONTypes} from "type-plus"import {Draft} from "../src/types/types-external"
describe("Draft<T>", () => { test("can use JSONTypes as T", () => { type A = Draft<JSONTypes> isType.equal<true, JSONTypes, A>() })
it("can use JSONArray as T", () => { type A = Draft<JSONArray> isType.equal<true, JSONArray, A>() })
it("can use Tuple as T", () => { type A = Draft<[string, number, JSONArray, JSONObject]> isType.equal<true, [string, number, JSONArray, JSONObject], A>() })})modified:src/types/types-external.ts+13 added-1 removed
28 unmodified lines29 * Set30 */31 type WeakReferences = IfAvailable<WeakMap<any, any>> | IfAvailable<WeakSet<any>>32 33-export type WritableDraft<T> = {-readonly [K in keyof T]: Draft<T[K]>}33+export type WritableDraft<T> = T extends any[]34+ ? number extends T["length"]35+ ? Draft<T[number]>[]36+ : WritableNonArrayDraft<T>37+ : WritableNonArrayDraft<T>38 39+type WritableNonArrayDraft<T> = {40+ -readonly [K in keyof T]: T[K] extends infer V41+ ? V extends object42+ ? Draft<V>43+ : V44+ : never45+}46+47 /** Convert a readonly type into a mutable type, if possible */48 export type Draft<T> = T extends PrimitiveType49 ? T50 : T extends AtomicObject201 unmodified linesmodified:package.json+1 added
87 unmodified lines8889909192939495969787 unmodified lines "rimraf": "^2.6.2", "seamless-immutable": "^7.1.3", "semantic-release": "^17.0.2", "tsup": "^6.7.0", "type-plus": "^7.6.2", "typescript": "^5.0.2", "vite": "^5.4.0", "vitest": "^2.0.0" }}modified:yarn.lock+32 added
1449 unmodified lines1450 version "6.4.0"1451 resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.0.tgz#b659d2ffbafa24baf5db1cdbb2c94a983ecd2784"1452 integrity sha512-gac8OEcQ2Li1dxIEWGZzsp2BitJxwkwcOm0zHAJLcPJaVvm58FRnk6RkuLRpU1EujipU2ZFODv2P9DLMfnV8mw==1453 1454+acorn@^8.8.2:1455+ version "8.15.0"1456+ resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.15.0.tgz#a360898bc415edaac46c8241f6383975b930b816"1457+ integrity sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==1458+1459 agent-base@6, agent-base@^6.0.2:1460 version "6.0.2"1461 resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"1462 integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==3288 unmodified lines4751 version "1.1.6"4752 resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"4753 integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==4754 4755+is-buffer@^2.0.5:4756+ version "2.0.5"4757+ resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.5.tgz#ebc252e400d22ff8d77fa09888821a24a658c191"4758+ integrity sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==4759+4760 is-callable@^1.2.7:4761 version "1.2.7"4762 resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.7.tgz#3bc2a85ea742d9e36205dcacdd72ca1fdc51b055"4763 integrity sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==3664 unmodified lines8428 commander "^2.20.0"8429 source-map "~0.6.1"8430 source-map-support "~0.5.12"8431 8432+tersify@^3.11.1:8433+ version "3.12.1"8434+ resolved "https://registry.yarnpkg.com/tersify/-/tersify-3.12.1.tgz#1aa5a709a02daba24d694f0896fb8a233f482361"8435+ integrity sha512-VwzXGHZSOB4T27s4uvh9v8FYrNXyfVz0nBQi28TDwrZoQwT8ZJUp1W2Ff73ekN07stJSb0D+pr6iXeNeFqTI6Q==8436+ dependencies:8437+ acorn "^8.8.2"8438+ is-buffer "^2.0.5"8439+ unpartial "^1.0.4"8440+8441 test-exclude@^7.0.1:8442 version "7.0.1"8443 resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-7.0.1.tgz#20b3ba4906ac20994e275bbcafd68d510264c2a2"8444 integrity sha512-pFYqmTw68LXVjeWJMST4+borgQP2AyMNbg1BpZh9LbyhUeNkeaPF9gzfPGUAnSMV3qPYdWUwDIjjCLiSDOl7vg==255 unmodified lines8700 version "0.8.1"8701 resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"8702 integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==8703 8704+type-plus@^7.6.2:8705+ version "7.6.2"8706+ resolved "https://registry.yarnpkg.com/type-plus/-/type-plus-7.6.2.tgz#76edc22b04e803c047df94c54a69ddbed7141b1d"8707+ integrity sha512-qUlXv9Y0/W56pg38m275IMD3WA03QbVoqNY16S3kmwtuA4gOT2iheyUdOp8NWrmXWpf7om98hzr7AZD/eW2jLA==8708+ dependencies:8709+ tersify "^3.11.1"8710+ unpartial "^1.0.4"8711+8712 typed-array-buffer@^1.0.3:8713 version "1.0.3"8714 resolved "https://registry.yarnpkg.com/typed-array-buffer/-/typed-array-buffer-1.0.3.tgz#a72395450a4869ec033fd549371b47af3a2ee536"8715 integrity sha512-nAYYwfY3qnzX30IkA6AQZjVbtK6duGontcQm1WSG1MD94YLqK0515GNApXkoxKOWMusVssAHWLh9SeaoefYFGw==86 unmodified lines8802 version "2.0.0"8803 resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"8804 integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==8805 8806+unpartial@^1.0.4:8807+ version "1.0.5"8808+ resolved "https://registry.yarnpkg.com/unpartial/-/unpartial-1.0.5.tgz#ade2b97d4fa309dc6a7fdca6a6fdbf76817fdd7e"8809+ integrity sha512-yAqaXcachjgZUnM2yIkf+4KJhmyuoj7stBvlnlZpB15OYVbKnLhgJfmLW7qkpzLHCdsm1bEFvhyN9hCmlZ3uuw==8810+8811 unset-value@^1.0.0:8812 version "1.0.0"8813 resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"8814 integrity sha1-g3aHP30jNRef+x5vw6jtDfyKtVk=399 unmodified lines