我试图让我的装饰器附加到一个属性上,以便typeof MyObject在调用时显示项目列表@MyProperty(MyObject, { /* public properties that are in MyObject */ })
我试过使用export function MyProperty<T extends Behavior>(component: typeof T, options?: Options<T>) {,但它给了我一个错误:
'T' 仅指一种类型,但在这里用作值。
我也试过InstanceType<T>这样使用:export function MyProperty<T extends Behavior>(component: InstanceType<T>, options?: Options<T>) {但它给了我这个错误:
类型“T”不满足约束“new (...args: any) => any”。
我也尝试过使用typeof Behavior而不是typeof T,但是它给出了Behavior而不是类中的项目扩展Behavior。
我不太确定该怎么做。如何在 的第二个参数中获取这些属性@MyProperty?
export type Options<T> = {
[P in keyof T]?: T[P]
}
export function MyProperty<T extends Behavior>(component: typeof T, options?: Options<T>) {
return (target: MyTarget, property: string): void => {
}
}
export class Item extends MyTarget {
@MyProperty(Mesh, {color: 'red'})
public mesh!: Mesh
}
export class Mesh extends Behavior {
public mesh!: ThreeMesh
public geometry!: Geometry
public color: string | number | Color = 0xffffff
}