打字稿编译器API-生成静态嵌套类

发布于 2025-01-24 02:39:22 字数 637 浏览 2 评论 0原文

可以像以下内容一样声明tysparcript中的嵌套静态类,如以下

export class Foo {
    public static readonly Bar = class {
        public static readonly FooBar: string = 'FooBar';
    }
}

使用函数createClassDeclaration从Typescript Compiler api生成一个静态类I时,

export class Foo {
    public static readonly class Bar {
        public static readonly FooBar: string = 'FooBar';
    }
}

声明 。节点。
在这里,我的编译

"compilerOptions": {
  "module": "commonjs",
  "target": "ESNext",
  "resolveJsonModule": true,
  "esModuleInterop": true
}

是我的问题是,如何创建一个静态类,如上一个代码示例中所示?

Nested static classes in TypeScript can be declared like the following

export class Foo {
    public static readonly Bar = class {
        public static readonly FooBar: string = 'FooBar';
    }
}

When using the function createClassDeclaration from the TypeScript compiler api to generate a static class I receive the following that doesn't compile

export class Foo {
    public static readonly class Bar {
        public static readonly FooBar: string = 'FooBar';
    }
}

I run my generation script with ts-node.
Here my compilerOptions

"compilerOptions": {
  "module": "commonjs",
  "target": "ESNext",
  "resolveJsonModule": true,
  "esModuleInterop": true
}

So my question is, how can I create a static class like shown in the first code example above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文