Skip to content

Commit

Permalink
fix: recursive issue with Draft and JSONTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Oct 30, 2022
1 parent 5721bb7 commit 7e2c3d1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"javascript.validate.enable": false,
"typescript.tsdk": "node_modules/typescript/lib",
"jest.enableInlineErrorMessages": true,
Expand Down
9 changes: 9 additions & 0 deletions __tests__/types/type-externals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {isType, 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>()
})
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"spec.ts": "^1.1.0",
"ts-jest": "^25.2.0",
"tsdx": "^0.12.3",
"type-plus": "^4.15.2",
"typescript": "^4.2.3"
}
}
4 changes: 3 additions & 1 deletion src/types/types-external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export type IfAvailable<T, Fallback = void> =
*/
type WeakReferences = IfAvailable<WeakMap<any, any>> | IfAvailable<WeakSet<any>>

export type WritableDraft<T> = {-readonly [K in keyof T]: Draft<T[K]>}
export type WritableDraft<T> = {
-readonly [K in keyof T]: T[K] extends object ? Draft<T[K]> : T[K]
}

/** Convert a readonly type into a mutable type, if possible */
export type Draft<T> = T extends PrimitiveType
Expand Down
32 changes: 32 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,11 @@ acorn@^7.1.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.0.tgz#949d36f2c292535da602283586c2477c57eb2d6c"
integrity sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==

acorn@^8.8.0:
version "8.8.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.1.tgz#0a3f9cbecc4ec3bea6f0a80b66ae8dd2da250b73"
integrity sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==

agent-base@4, agent-base@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee"
Expand Down Expand Up @@ -5849,6 +5854,11 @@ is-buffer@^1.1.5:
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==

is-buffer@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.5.tgz#ebc252e400d22ff8d77fa09888821a24a658c191"
integrity sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==

is-callable@^1.1.4, is-callable@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.0.tgz#83336560b54a38e35e3a2df7afd0454d691468bb"
Expand Down Expand Up @@ -11224,6 +11234,15 @@ terser@^4.1.2, terser@^4.6.2:
source-map "~0.6.1"
source-map-support "~0.5.12"

tersify@^3.10.2:
version "3.10.5"
resolved "https://registry.yarnpkg.com/tersify/-/tersify-3.10.5.tgz#eb2b230e7725481129b7fa349f2ce2683bd8a9ec"
integrity sha512-dLgsTbGVH/6Z+KU4d+NqMmsMFRwRmTFNxsl5vKGkUmaSQ0TTAwnv+Hck5S8Pdn5bcZSyjR3aTvvetJ7ZUs+ZYg==
dependencies:
acorn "^8.8.0"
is-buffer "^2.0.5"
unpartial "^1.0.0"

test-exclude@^5.2.3:
version "5.2.3"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-5.2.3.tgz#c3d3e1e311eb7ee405e092dac10aefd09091eac0"
Expand Down Expand Up @@ -11576,6 +11595,14 @@ type-fest@^0.8.1:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"
integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==

type-plus@^4.15.2:
version "4.15.2"
resolved "https://registry.yarnpkg.com/type-plus/-/type-plus-4.15.2.tgz#2d97273bde0c921845ae70a0d1cef075a7c0cfc1"
integrity sha512-5hEzFXMHOK/p5hVhNmgy7CIxUjTIK9a/NOw0pDbc4tb7LXm9JLwLEH0QdGWU5fGPp5l05rtPZfjdSOPqfAyX9w==
dependencies:
tersify "^3.10.2"
unpartial "^1.0.3"

typedarray-to-buffer@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"
Expand Down Expand Up @@ -11694,6 +11721,11 @@ universalify@^2.0.0:
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

unpartial@^1.0.0, unpartial@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/unpartial/-/unpartial-1.0.4.tgz#56490ed475105110cee61890a80c5da394741833"
integrity sha512-xY8319WOQcRDRVFWvTty2YJXKvM8XRPehqWZUd7k/BatpbuitI4Jd+2xlwjTZbZScSvT75TnUsUmy5uwFa3o0g==

unpipe@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
Expand Down

0 comments on commit 7e2c3d1

Please sign in to comment.