首页 > 解决方案 > 如何实现像 Babel 这样的插件注册?

问题描述

如何实现像 Babel 这样的插件注册?打字稿支持吗?如果不是,为什么?

打字稿游乐场

class PluginA {
    constructor(platform: Platform, options: { a: string }) { }
    print() { }
}

class PluginB {
    constructor(platform: Platform, options: { b: number }) { }
    print() { }
}

const p = new Platform({
    pluginSettings: [
        [PluginA, { a: 123 }], // Expect an error but no
        [PluginB, { b: 'abc' }], // Expect an error but no
    ],
})

我希望[PluginA, { a: 123 }]has type of[typeof PluginA, { a: string }][PluginB, { a: 'abc' }]has type of [typeof PluginB, { a: number }],但事实并非如此。

标签: javascripttypescript

解决方案


推荐阅读