#how solve this ? incompatible fonction parameters ? how satify function with generic params

16 messages · Page 1 of 1 (latest)

urban temple
#

hi, how i can solve this ? how i can use generic function parameters to satisfy a function with different params ?

white axleBOT
#
jonLepage#7984

Preview:```ts
export interface ParamBase<V = any> {
defaultValue: V
onValidate: (value: V) => void
onUnmount?: () => void
onchange?: (value: V) => void
}

export interface FunctionType<
P extends ParamBase = ParamBase

extends Function {
(props: P): void
}
...```

molten creek
#

your example is very complex

#

your comment on the last line is wrong

#
const x: FunctionType<ParamBase> = Foo; // compile-time error
#

So Foo doesn't satisfy FunctionType<ParamBase>

#

because to safely call Foo you need more arguments than you would need to safely call FunctionType<ParamBase>

white axleBOT
#
webstrand#8856

Preview:```ts
export interface ParamBase<V = any> {
defaultValue: V
onValidate: (value: V) => void
onUnmount?: () => void
onchange?: (value: V) => void
}

export interface FunctionType<
P extends ParamBase = ParamBase

extends Function {
(props: P): void
}
...```

molten creek
#

solves the first issue, but functionType still isn't callable because it doesn't have enough arguments to be callable

#

the other way to solve this is by modifying Foo:

interface IFoo extends ParamBase {
    aaa?:8
}

if you make aaa optional, it isn't something that must be passed, so assignment works out

urban temple
white axleBOT
#
jonLepage#7984

Preview:```ts
export interface ParamBase<V = any> {
defaultValue: V
onValidate: (value: V) => void
onUnmount?: () => void
onchange?: (value: V) => void
}

export interface FunctionType<
P extends ParamBase = ParamBase

extends Function {
(props: P): void
}
...```

molten creek
#

you've told typescript functionType: T|FunctionType so either one is acceptable

urban temple
molten creek
#

I don't recognize whatever pattern you're trying to apply here, so I can't give any guidance in that regard

#

might be time for a !helper