diff --git a/.changeset/fluffy-crabs-exercise.md b/.changeset/fluffy-crabs-exercise.md new file mode 100644 index 000000000..3b54d3ce7 --- /dev/null +++ b/.changeset/fluffy-crabs-exercise.md @@ -0,0 +1,5 @@ +--- +"mobx": minor +--- + +Replace any with a generic in Set methods diff --git a/packages/mobx/__tests__/v5/base/typescript-tests.ts b/packages/mobx/__tests__/v5/base/typescript-tests.ts index 2ce5ef056..c65f66736 100644 --- a/packages/mobx/__tests__/v5/base/typescript-tests.ts +++ b/packages/mobx/__tests__/v5/base/typescript-tests.ts @@ -2054,6 +2054,19 @@ test("type inference of the action callback", () => { } }) +test("TS - type inference of Set", () => { + const set = observable.set() + set.add(1) + set.has(1) + set.delete(1) + // @ts-expect-error + set.add("1") + // @ts-expect-error + set.has("1") + // @ts-expect-error + set.delete("1") +}) + test("TS - type inference of observe & intercept functions", () => { const array = [1, 2] const object = { numberKey: 1, stringKey: "string" } diff --git a/packages/mobx/src/types/observableset.ts b/packages/mobx/src/types/observableset.ts index 062829acb..05171775a 100644 --- a/packages/mobx/src/types/observableset.ts +++ b/packages/mobx/src/types/observableset.ts @@ -159,7 +159,7 @@ export class ObservableSet implements Set, IInterceptable>(this, { type: DELETE, @@ -202,7 +202,7 @@ export class ObservableSet implements Set, IInterceptable