我想输入TS Class属性装饰器,这样第一个函数将受到第二个函数中键名的限制,如下所示:
interface A {
name: "a" | "b";
surname: "c";
}
const x2 = <K extends keyof A, Type extends A[K]>(val: Type) => (key: K) => {}
x2("aaa")("surname"); // "aaa" should be type "c" but is "a" | "b" | "c"
它在这里正常工作,但仅在一个功能中起作用
const x = <K extends keyof A, Type extends A[K]>(key: K, val: Type) => { }
x("surname", "xxx"); // "xxx" is limited to "c"
在最终版本中,我想在装饰类型中使用它:
export const MyDecorator = <
S extends State,
Key extends keyof MyInterface,
Type extends MyInterface[Key]
>(
defaultValue: Type
) => (target: S, key: Key) => {
};
@MyDecorator("li") // limit the default value here
something: Something;