mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] types: make component generic types optional
In most cases, we just want Component<any, Env>. But since it was so annoying to have always the type Env, we actually used Component<any,any> everywhere. With this commit, the generic types have a default (and their order is swapped), so we can simply use Component in most cases, and Component<Props> when we want to type the props.
This commit is contained in:
+6
-6
@@ -22,7 +22,7 @@ import { Observer } from "./core/observer";
|
||||
* trigger a rerendering of the current component.
|
||||
*/
|
||||
export function useState<T>(state: T): T {
|
||||
const component: Component<any, any> = Component.current!;
|
||||
const component: Component = Component.current!;
|
||||
const __owl__ = component.__owl__;
|
||||
if (!__owl__.observer) {
|
||||
__owl__.observer = new Observer();
|
||||
@@ -37,7 +37,7 @@ export function useState<T>(state: T): T {
|
||||
function makeLifecycleHook(method: string, reverse: boolean = false) {
|
||||
if (reverse) {
|
||||
return function(cb) {
|
||||
const component: Component<any, any> = Component.current!;
|
||||
const component: Component = Component.current!;
|
||||
if (component.__owl__[method]) {
|
||||
const current = component.__owl__[method];
|
||||
component.__owl__[method] = function() {
|
||||
@@ -50,7 +50,7 @@ function makeLifecycleHook(method: string, reverse: boolean = false) {
|
||||
};
|
||||
} else {
|
||||
return function(cb) {
|
||||
const component: Component<any, any> = Component.current!;
|
||||
const component: Component = Component.current!;
|
||||
if (component.__owl__[method]) {
|
||||
const current = component.__owl__[method];
|
||||
component.__owl__[method] = function() {
|
||||
@@ -66,7 +66,7 @@ function makeLifecycleHook(method: string, reverse: boolean = false) {
|
||||
|
||||
function makeAsyncHook(method: string) {
|
||||
return function(cb) {
|
||||
const component: Component<any, any> = Component.current!;
|
||||
const component: Component = Component.current!;
|
||||
if (component.__owl__[method]) {
|
||||
const current = component.__owl__[method];
|
||||
component.__owl__[method] = function(...args) {
|
||||
@@ -96,7 +96,7 @@ export const onWillUpdateProps = makeAsyncHook("willUpdatePropsCB");
|
||||
*/
|
||||
interface Ref {
|
||||
el: HTMLElement | null;
|
||||
comp: Component<any, any> | null;
|
||||
comp: Component | null;
|
||||
}
|
||||
|
||||
export function useRef(name: string): Ref {
|
||||
@@ -111,7 +111,7 @@ export function useRef(name: string): Ref {
|
||||
}
|
||||
return null;
|
||||
},
|
||||
get comp(): Component<any, any> | null {
|
||||
get comp(): Component | null {
|
||||
const val = __owl__.refs && __owl__.refs[name];
|
||||
return val instanceof Component ? val : null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user