diff --git a/CHANGELOG.md b/CHANGELOG.md index 28aa5dd5..f30b93ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 1.10.2 + +- Fixed some types so set transformations are compatible with TypeSscript 5.5 once more. + ## 1.10.1 - Some more minor optimizations, for example creating models should be around 10% faster now. diff --git a/apps/benchmark/package.json b/apps/benchmark/package.json index 918d269c..386c3e6e 100644 --- a/apps/benchmark/package.json +++ b/apps/benchmark/package.json @@ -25,6 +25,6 @@ "@types/benchmark": "^2.1.5", "cross-env": "^7.0.3", "shx": "^0.3.4", - "typescript": "^5.4.5" + "typescript": "^5.5.2" } } diff --git a/apps/site/package.json b/apps/site/package.json index e530a278..a34a67f4 100644 --- a/apps/site/package.json +++ b/apps/site/package.json @@ -41,7 +41,7 @@ "@types/uuid": "^10.0.0", "raw-loader": "^4.0.2", "shx": "^0.3.4", - "typescript": "^5.4.5" + "typescript": "^5.5.2" }, "browserslist": { "production": [ diff --git a/package.json b/package.json index aaec2422..8cc2874e 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "prettier": "^3.3.2", "prettier-plugin-organize-imports": "^3.2.4", "turbo": "^2.0.4", - "typescript": "^5.4.5", + "typescript": "^5.5.2", "typescript-eslint": "^7.13.1" }, "packageManager": "yarn@4.2.2" diff --git a/packages/lib/package.json b/packages/lib/package.json index 2e93d8a5..a9c53999 100755 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -1,6 +1,6 @@ { "name": "mobx-keystone", - "version": "1.10.1", + "version": "1.10.2", "description": "A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more", "keywords": [ "mobx", @@ -86,7 +86,7 @@ "ts-jest": "^29.1.5", "ts-node": "^10.9.2", "typedoc": "^0.26.0", - "typescript": "^5.4.5", + "typescript": "^5.5.2", "vite": "^5.3.1" }, "dependencies": { diff --git a/packages/lib/src/transforms/asSet.ts b/packages/lib/src/transforms/asSet.ts index 7031eb2c..6627b6c6 100644 --- a/packages/lib/src/transforms/asSet.ts +++ b/packages/lib/src/transforms/asSet.ts @@ -1,7 +1,8 @@ +import { ObservableSet } from "mobx" import type { ModelPropTransform } from "../modelShared/prop" import { asSet } from "../wrappers/asSet" -const _arrayToSetTransform: ModelPropTransform, Set> = { +const _arrayToSetTransform: ModelPropTransform, ObservableSet> = { transform({ originalValue: arr, cachedTransformedValue: cachedSet }) { return cachedSet ?? asSet(arr) }, @@ -14,4 +15,4 @@ const _arrayToSetTransform: ModelPropTransform, Set> = { } export const arrayToSetTransform = () => - _arrayToSetTransform as ModelPropTransform, Set> + _arrayToSetTransform as ModelPropTransform, Set | ObservableSet> diff --git a/packages/lib/src/utils/index.ts b/packages/lib/src/utils/index.ts index 98b5f504..9c43694f 100644 --- a/packages/lib/src/utils/index.ts +++ b/packages/lib/src/utils/index.ts @@ -196,7 +196,10 @@ export function assertIsObservableArray( /** * @internal */ -export function assertIsMap(value: unknown, argName: string): asserts value is Map { +export function assertIsMap( + value: unknown, + argName: string +): asserts value is Map | ObservableMap { if (!isMap(value)) { throw failure(`${argName} must be a map`) } @@ -205,7 +208,10 @@ export function assertIsMap(value: unknown, argName: string): asserts value is M /** * @internal */ -export function assertIsSet(value: unknown, argName: string): asserts value is Set { +export function assertIsSet( + value: unknown, + argName: string +): asserts value is Set | ObservableSet { if (!isSet(value)) { throw failure(`${argName} must be a set`) } diff --git a/packages/lib/src/wrappers/ArraySet.ts b/packages/lib/src/wrappers/ArraySet.ts index 4e7c2416..e908e1b3 100644 --- a/packages/lib/src/wrappers/ArraySet.ts +++ b/packages/lib/src/wrappers/ArraySet.ts @@ -89,6 +89,41 @@ export class ArraySet } readonly [Symbol.toStringTag] = "ArraySet" + + union(other: ReadonlySetLike): Set { + const s = new Set(this) + return s.union(other) + } + + intersection(other: ReadonlySetLike): Set { + const s = new Set(this) + return s.intersection(other) + } + + difference(other: ReadonlySetLike): Set { + const s = new Set(this) + return s.difference(other) + } + + symmetricDifference(other: ReadonlySetLike): Set { + const s = new Set(this) + return s.symmetricDifference(other) + } + + isSubsetOf(other: ReadonlySetLike): boolean { + const s = new Set(this) + return s.isSubsetOf(other) + } + + isSupersetOf(other: ReadonlySetLike): boolean { + const s = new Set(this) + return s.isSupersetOf(other) + } + + isDisjointFrom(other: ReadonlySetLike): boolean { + const s = new Set(this) + return s.isDisjointFrom(other) + } } /** diff --git a/packages/lib/src/wrappers/asSet.ts b/packages/lib/src/wrappers/asSet.ts index d36cb125..aa62206b 100644 --- a/packages/lib/src/wrappers/asSet.ts +++ b/packages/lib/src/wrappers/asSet.ts @@ -146,7 +146,7 @@ export function asSet(array: Array): ObservableSet & { dataObject: type * * @param set */ -export function setToArray(set: Set): Array { +export function setToArray(set: Set | ObservableSet): Array { assertIsSet(set, "set") const dataObject = (set as Set & { dataObject: Array }).dataObject diff --git a/packages/lib/test/model/propTransform.test.ts b/packages/lib/test/model/propTransform.test.ts index c60d0a12..5f0075ba 100644 --- a/packages/lib/test/model/propTransform.test.ts +++ b/packages/lib/test/model/propTransform.test.ts @@ -1,4 +1,4 @@ -import { set, toJS } from "mobx" +import { ObservableSet, set, toJS } from "mobx" import { assert, _ } from "spec.ts" import { arrayToMapTransform, @@ -309,7 +309,7 @@ test("prop with arr->set transform", () => { set: set1, }) - assert(t.set, _ as Set) + assert(t.set, _ as Set | ObservableSet) expect(t.set.has(1)).toBe(true) expect(t.set).not.toBe(set1) // should not be cached expect(t.set).toBe(t.set) // should be cached @@ -331,7 +331,7 @@ test("prop with arr->set transform", () => { t.setSet(set2) - assert(t.set, _ as Set) + assert(t.set, _ as Set | ObservableSet) expect(t.set.has(2)).toBe(true) expect(t.set).not.toBe(set2) // should not be cached expect(t.set).toBe(t.set) // should be cached @@ -340,7 +340,7 @@ test("prop with arr->set transform", () => { const tsn = getSnapshot(t) assert(tsn.set, _ as Array) const tfsn = fromSnapshot(T, tsn) - assert(tfsn.set, _ as Set) + assert(tfsn.set, _ as Set | ObservableSet) expect(toJS(t.$.set)).toEqual([2]) t.setNumberArr([4]) diff --git a/packages/mobx-keystone-yjs/package.json b/packages/mobx-keystone-yjs/package.json index aad9b3bf..1d680c21 100644 --- a/packages/mobx-keystone-yjs/package.json +++ b/packages/mobx-keystone-yjs/package.json @@ -79,7 +79,7 @@ "spec.ts": "^1.1.3", "ts-jest": "^29.1.5", "ts-node": "^10.9.2", - "typescript": "^5.4.5", + "typescript": "^5.5.2", "vite": "^5.3.1" }, "dependencies": { diff --git a/yarn.lock b/yarn.lock index 52128037..0f5a1c4b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7493,7 +7493,7 @@ __metadata: mobx-state-tree: "npm:^6.0.0" shx: "npm:^0.3.4" tslib: "npm:^2.6.3" - typescript: "npm:^5.4.5" + typescript: "npm:^5.5.2" peerDependencies: mobx: ^6.0.0 languageName: unknown @@ -16375,7 +16375,7 @@ __metadata: ts-jest: "npm:^29.1.5" ts-node: "npm:^10.9.2" tslib: "npm:^2.6.3" - typescript: "npm:^5.4.5" + typescript: "npm:^5.5.2" vite: "npm:^5.3.1" peerDependencies: mobx: ^6.0.0 || ^5.0.0 || ^4.0.0 @@ -16411,7 +16411,7 @@ __metadata: ts-toolbelt: "npm:^9.6.0" tslib: "npm:^2.6.3" typedoc: "npm:^0.26.0" - typescript: "npm:^5.4.5" + typescript: "npm:^5.5.2" vite: "npm:^5.3.1" peerDependencies: mobx: ^6.0.0 || ^5.0.0 || ^4.0.0 @@ -19868,7 +19868,7 @@ __metadata: prettier: "npm:^3.3.2" prettier-plugin-organize-imports: "npm:^3.2.4" turbo: "npm:^2.0.4" - typescript: "npm:^5.4.5" + typescript: "npm:^5.5.2" typescript-eslint: "npm:^7.13.1" yjs: "npm:^13.6.18" languageName: unknown @@ -20469,7 +20469,7 @@ __metadata: react-dom: "npm:^18.3.1" remotedev: "npm:^0.2.9" shx: "npm:^0.3.4" - typescript: "npm:^5.4.5" + typescript: "npm:^5.5.2" utf-8-validate: "npm:^5.0.10" y-webrtc: "npm:^10.3.0" peerDependencies: @@ -22023,23 +22023,23 @@ __metadata: languageName: node linkType: hard -"typescript@npm:^5.0.0, typescript@npm:^5.0.4, typescript@npm:^5.4.5": - version: 5.4.5 - resolution: "typescript@npm:5.4.5" +"typescript@npm:^5.0.0, typescript@npm:^5.0.4, typescript@npm:^5.5.2": + version: 5.5.2 + resolution: "typescript@npm:5.5.2" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10c0/2954022ada340fd3d6a9e2b8e534f65d57c92d5f3989a263754a78aba549f7e6529acc1921913560a4b816c46dce7df4a4d29f9f11a3dc0d4213bb76d043251e + checksum: 10c0/8ca39b27b5f9bd7f32db795045933ab5247897660627251e8254180b792a395bf061ea7231947d5d7ffa5cb4cc771970fd4ef543275f9b559f08c9325cccfce3 languageName: node linkType: hard -"typescript@patch:typescript@npm%3A^5.0.0#optional!builtin, typescript@patch:typescript@npm%3A^5.0.4#optional!builtin, typescript@patch:typescript@npm%3A^5.4.5#optional!builtin": - version: 5.4.5 - resolution: "typescript@patch:typescript@npm%3A5.4.5#optional!builtin::version=5.4.5&hash=5adc0c" +"typescript@patch:typescript@npm%3A^5.0.0#optional!builtin, typescript@patch:typescript@npm%3A^5.0.4#optional!builtin, typescript@patch:typescript@npm%3A^5.5.2#optional!builtin": + version: 5.5.2 + resolution: "typescript@patch:typescript@npm%3A5.5.2#optional!builtin::version=5.5.2&hash=b45daf" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10c0/db2ad2a16ca829f50427eeb1da155e7a45e598eec7b086d8b4e8ba44e5a235f758e606d681c66992230d3fc3b8995865e5fd0b22a2c95486d0b3200f83072ec9 + checksum: 10c0/6721ac8933a70c252d7b640b345792e103d881811ff660355617c1836526dbb71c2044e2e77a8823fb3570b469f33276875a4cab6d3c4de4ae7d7ee1c3074ae4 languageName: node linkType: hard