const defaultArg = (arg: {}) => ({})
type Arg<T> = (arg: T) => T;
type Default = Arg<{}>;
interface Test {
(): void;
<T>(arg: Arg<T>): void;
}
const test: Test = <T>(arg: Arg<T> = defaultArg) => {
//do something
}
TSError:
Type '(arg: {}) => {}' is not assignable to type 'Arg<T>'. Type '{}' is not assignable to type 'T'. '{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
我想根据Arg
的值确定传递给类型arg
的通用参数。如果未定义arg
,我想将{}
传递为类型Arg
而不是T
的通用参数。