diff --git a/index.d.ts b/index.d.ts index a5ae519..c65aa30 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,2 +1,2 @@ -declare function isEqual(a: any, b: B): a is B; +declare function isEqual(a: A, b: B): boolean; export = isEqual; diff --git a/test/typescript/sample-usage.tsx b/test/typescript/sample-usage.tsx index d9c7b91..0bd46e1 100644 --- a/test/typescript/sample-usage.tsx +++ b/test/typescript/sample-usage.tsx @@ -31,6 +31,14 @@ class TestChild extends React.Component { } } +// `equal` must return a plain `boolean`, not a type guard (`a is B`): after a +// `false` result, a guard narrows `prev` to `never`, so `prev.text` would not +// compile (#130). +export function changedText(prev: ITodo, next: ITodo): string | null { + if (equal(prev, next)) return null; + return prev.text; +} + class TestContainer extends React.Component { render() { return testArr.map((item) => );