Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect Metadata demo有错 #252

Open
ssxsite opened this issue Jan 13, 2022 · 0 comments
Open

Reflect Metadata demo有错 #252

ssxsite opened this issue Jan 13, 2022 · 0 comments

Comments

@ssxsite
Copy link

ssxsite commented Jan 13, 2022

(这篇文章的demo有问题:https://jkchao.github.io/typescript-book-chinese/tips/metadata.html#%E5%9F%BA%E7%A1%80))。
原文:
譬如在 vue-property-decorator 6.1 及其以下版本中,通过使用 Reflect.getMetadata API,Prop Decorator 能获取属性类型传至 Vue,简要代码如下:

function Prop(): PropertyDecorator { return (target, key: string) => { const type = Reflect.getMetadata('design:type', target, key); console.log(${key} type: ${type.name}`);
// other...
};
}

class SomeClass {
@prop()
public Aprop!: string;
}
`

代码运行有问题。改成如下则没问题:

function Prop(): Function { return (target, key: string) => { const type = Reflect.getMetadata('design:type', target, key); console.log(${key} type: ${type.name}`);
// other...
};
}

class SomeClass {
@prop()
public Aprop!: string;
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant