转自ts中箭头函数用泛型表示,6种方法
const foo = <T,>(x: T): T => x;
const foo = <T extends {}>(x: T): T => x;
const foo = <T extends Record<string, unknown>>(x: T): T => x;
const foo: <T>(x: T) => T = x => x;
const identity = <T,>(arg: T): T => {
console.log(arg);
return arg;
};
const renderAuthorize = <T>(Authorized: T): ((currentAuthority: CurrentAuthorityType) => T) => (
currentAuthority: CurrentAuthorityType,
): T => {
return
};
function myRef<T>(value:T) {
return customRef((track, trigger) => {
return {
get() {
track();
return value;
},
set(newVal) {
console.log('我是myRef,我被重新赋值为:' + newVal);
value = newVal;
trigger();
}
}
})
}
const myRef2 = <T>(value: T) => {
return customRef((track, trigger) => {
return {
get() {
track();
return value;
},
set(newVal) {
console.log('我是myRef,我被重新赋值为:' + newVal);
value = newVal;
trigger();
}
}
})
}