Skip to content

Commit

Permalink
Fix tsc errors in src and keep demo errors the same as before
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewiggins committed May 1, 2023
1 parent 2ba3545 commit 924e023
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
3 changes: 2 additions & 1 deletion docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"jsx": "react-jsx",
"jsxImportSource": "preact",
"module": "esnext"
}
},
"exclude": ["node_modules", "dist"]
}
6 changes: 5 additions & 1 deletion mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
},
"minify": {
"mangle": {
"reserved": ["useSignal", "useComputed", "useSignalEffect"],
"reserved": [
"useSignal",
"useComputed",
"useSignalEffect"
],
"keep_classnames": true,
"properties": {
"regex": "^_[^_]",
Expand Down
13 changes: 7 additions & 6 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,22 +669,23 @@ function endEffect(this: Effect, prevContext?: Computed | Effect) {
endBatch();
}

type EffectCleanup = () => unknown;
declare class Effect {
_compute?: () => void | (() => void);
_cleanup?: () => void;
_compute?: () => unknown | EffectCleanup;
_cleanup?: () => unknown;
_sources?: Node;
_nextBatchedEffect?: Effect;
_flags: number;

constructor(compute: () => void | (() => void));
constructor(compute: () => unknown | EffectCleanup);

_callback(): void;
_start(): () => void;
_notify(): void;
_dispose(): void;
}

function Effect(this: Effect, compute: () => void | (() => void)) {
function Effect(this: Effect, compute: () => unknown | EffectCleanup) {
this._compute = compute;
this._cleanup = undefined;
this._sources = undefined;
Expand All @@ -700,7 +701,7 @@ Effect.prototype._callback = function () {

const cleanup = this._compute();
if (typeof cleanup === "function") {
this._cleanup = cleanup;
this._cleanup = cleanup as EffectCleanup;
}
} finally {
finish();
Expand Down Expand Up @@ -738,7 +739,7 @@ Effect.prototype._dispose = function () {
}
};

function effect(compute: () => void | (() => void)): () => void {
function effect(compute: () => unknown | EffectCleanup): () => void {
const effect = new Effect(compute);
try {
effect._callback();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/signal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ describe("computed()", () => {
});

it("should disallow setting signal's value", () => {
const v: number = 123;
const v = 123;
const a: Signal = signal(v);
const c: Signal = computed(() => a.value++);

Expand Down
3 changes: 2 additions & 1 deletion packages/react/test/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export function checkConsoleErrorLogs(): void {
if (errorSpy.called) {
let message: string;
if (errorSpy.firstCall.args[0].toString().includes("%s")) {
message = consoleFormat(...errorSpy.firstCall.args);
const firstArg = errorSpy.firstCall.args[0];
message = consoleFormat(firstArg, ...errorSpy.firstCall.args.slice(1));
} else {
message = errorSpy.firstCall.args.join(" ");
}
Expand Down
7 changes: 1 addition & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,5 @@
"@preact/signals-react": ["./packages/react/src/index.ts"]
}
},
"include": [
"packages/*/src/**/*",
"packages/*/test/**/*",
"test/**/*",
"global.d.ts"
]
"exclude": ["docs", "packages/*/dist/**"]
}

0 comments on commit 924e023

Please sign in to comment.