mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] hooks: remove useEffect type circular dependency
`useEffect` type is not compatible with later versions of Typescript. (I tried with Typescript 5.2, I didn't check which specific version had the breaking change) This prevents other projects using owl (such as o-spreadsheet) to upgrade their own version of Typescript. `<T extends [...T]>` raises the two following errors: `Type parameter 'T' has a circular constraint.ts(2313)` `A rest element type must be an array type.`
This commit is contained in:
committed by
Sam Degueldre
parent
035895b043
commit
eec7cc4ea7
@@ -641,6 +641,56 @@ describe("hooks", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test("effect types are inferred from dependencies", async () => {
|
||||
// @ts-ignore (declared but never used)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
class MyComponent extends Component {
|
||||
static template = xml`<div/>`;
|
||||
|
||||
setup() {
|
||||
useEffect(
|
||||
(a, b) => {
|
||||
expectType<number>(a);
|
||||
expectType<string>(b);
|
||||
},
|
||||
() => [3, "hello"]
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("effect type allows an effect with partial dependencies parameters", async () => {
|
||||
// @ts-ignore (declared but never used)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
class MyComponent extends Component {
|
||||
static template = xml`<div/>`;
|
||||
|
||||
setup() {
|
||||
useEffect(
|
||||
(a) => {
|
||||
expectType<number>(a);
|
||||
},
|
||||
() => [3, "hello"]
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("effect type allows an effect with no dependency parameter", async () => {
|
||||
// @ts-ignore (declared but never used)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
class MyComponent extends Component {
|
||||
static template = xml`<div/>`;
|
||||
|
||||
setup() {
|
||||
useEffect(
|
||||
() => {},
|
||||
() => [3, "hello"]
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("properly behaves when the effect function throws", async () => {
|
||||
let originalconsoleError = console.error;
|
||||
let originalconsoleWarn = console.warn;
|
||||
@@ -673,3 +723,5 @@ describe("hooks", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function expectType<T>(t: T) {}
|
||||
|
||||
Reference in New Issue
Block a user