如何为typescript vue类使用构造函数选项?

如何为typescript vue类使用构造函数选项?,typescript,vue.js,Typescript,Vue.js,给定以下代码段 给出了一个编译错误 ERROR in C:/dev/AscendXYZ/Ascend.Wammo.RadarIngestor/apps/Ascend.Wammo.Dashboard/src/components/BirdControlMap.tsx 32:1 Unable to resolve signature of class decorator when called as an expression. Type '<VC extends VueClass<

给定以下代码段

给出了一个编译错误

ERROR in C:/dev/AscendXYZ/Ascend.Wammo.RadarIngestor/apps/Ascend.Wammo.Dashboard/src/components/BirdControlMap.tsx
32:1 Unable to resolve signature of class decorator when called as an expression.
  Type '<VC extends VueClass<Vue>>(target: VC) => VC' is missing the following properties from type 'typeof MapLayout': extend, nextTick, set, delete, and 9 more.
    30 | }
    31 |
  > 32 | @Component
       | ^
    33 | export default class MapLayout extends Vue {
    34 |
    35 |     constructor(options: MapLayoutOptions) {
C:/dev/AscendXYZ/Ascend.Wammo.RadarIngestor/apps/Ascend.Wammo.Dashboard/src/components/BirdControlMap.tsx中的
错误
32:1作为表达式调用时无法解析类装饰器的签名。
Type'(target:VC)=>VC'缺少类型“typeof MapLayout”中的以下属性:extend、nextTick、set、delete和其他9。
30 | }
31 |
>32 |@组件
| ^
33 |导出默认类MapLayout扩展Vue{
34 |
35 |构造函数(选项:MapLayoutOptions){
有没有办法在vue/typescript中使用构造函数选项?比如我在jsx标记上获得intellisense?

这里有一个解决方案

interface MapLayoutOptions{
    subscriberId: string;
    radarId: string;
    zoneGroupId: string;
    interval: number;
    apiEndpoint: string;
}

export abstract class TsxComponent<P> extends Vue {
    private vueTsxProps!: Readonly<{}> & Readonly<P>;
}

declare global {
    namespace JSX {
        interface ElementAttributesProperty { vueTsxProps: {}; }
    }
}

@Component
export default class MapLayout extends TsxComponent<MapLayoutOptions> {
}
接口映射选项{
subscriberId:字符串;
拉达里德:字符串;
zoneGroupId:字符串;
间隔:数字;
apiEndpoint:字符串;
}
导出抽象类TsxComponent

扩展Vue{ 私有vueTsxProps!:只读&只读

; } 宣布全球{ 名称空间JSX{ 接口元素属性属性{vueTsxProps:{};} } } @组成部分 导出默认类MapLayout扩展TsxComponent{ }


类型检查是确保接口属性得到实现,并为tsx元素提供intellisense。

如果不使用类组件,则该功能非常有效(经过轻度测试).不确定是否支持类组件我也发现了这一点,并查看了代码库,然后想。为什么需要这么多代码来支持它,并且认为它一定已经过时了。我真的想坚持使用typescript中的类(这就是我的世界)。我在下面提供了一个似乎相当简单且有效的解决方案。我正在启动一个Vue项目,并在两者之间进行考虑。不幸的是,clas组件背后似乎没有社区支持(jsx的支持也很弱,但至少它似乎可行)您可能对此感兴趣:似乎类组件将被删除:感谢链接。很有趣。但是使用typescript和@component decorators,它不仅仅是合成糖,而且编译成vue理解的东西吗?我刚刚开始了一个项目,发现我让tsx和组件能够在没有重大错误的情况下快速工作问题。