简体   繁体   English

如何强制我的自定义 tslint 规则使用与 tslint 正在使用的相同版本的打字稿模块

[英]how do I force my custom tslint rule to use the same version of the typescript module as the one tslint is using

I'm most likely doing something very wrong, but I can't figure out what.我很可能做错了什么,但我不知道是什么。

In my custom rule, I'm checking the SyntaxKind of a Node to control my flow, like so:在我的自定义规则中,我正在检查节点的 SyntaxKind 以控制我的流程,如下所示:

import * as ts from "typescript"

function processPropertyName(pn: ts.PropertyName) {
    switch (pn.kind) {
        case ts.SyntaxKind.Identifier:
        case ts.SyntaxKind.StringLiteral:
            //doX
            break
        case ts.SyntaxKind.NumericLiteral:
            //doY
            break
    }
}

I have installed typescript as a module this works fine when I'm developing and testing the rule.我已经将打字稿作为模块安装,这在我开发和测试规则时工作正常。 However, when I publish the package and use it in another project the SyntaxKind values are messed up.但是,当我发布包并在另一个项目中使用它时,SyntaxKind 值被搞乱了。 for example: NumericalLiteral has value 8 in my environment, but not in the consuming environment.例如:NumericalLiteral 在我的环境中的值为 8,但在消费环境中不是。 Most likely because another version of the typescript package is used.很可能是因为使用了另一个版本的 typescript 包。 But how can I make sure that the typescript package that I am importing in my rule file is the same as the one that is being used to parse the source file?但是如何确保我在规则文件中导入的打字稿包与用于解析源文件的打字稿包相同?

never mind, I found the solution:)没关系,我找到了解决方案:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM