#how solve this ? incompatible fonction parameters ? how satify function with generic params
16 messages · Page 1 of 1 (latest)
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
}
...```
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>
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
}
...```
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
ya i find another approach , little better , i can keep my type, but it allow any function params 😔
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
}
...```
you've told typescript functionType: T|FunctionType so either one is acceptable
yes am lost.
i just trying to allow generic function to be wraped, sry for complexity.
The idea look like this but i think i will need think more