cevek / ttypescript

Over TypeScript tool to use custom transformers in the tsconfig.json
1.53k stars 56 forks source link

Any way to ignore some diagnostics? #51

Closed anion155 closed 5 years ago

anion155 commented 5 years ago

I'm trying to implement transformer for operators overloading. It does work. But I can't get rid from diagnostic errors. Is there any way it could be done?

Simple transformer:

export default function (program: ts.Program, config?: PluginConfig) {
  const diagnostics = ts.getPreEmitDiagnostics(program);
  return (ctx: ts.TransformationContext) => {
    return (sourceFile: ts.SourceFile) => {
      function visitor(node: ts.Node): ts.Node {
        if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.PlusToken) {
              console.log('Found plus in:', type.getSymbol().escapedName);
              return ts.createCall(
                ts.createPropertyAccess(node.left, '__add'),
                [], [node.right]
              );
            }
          }
        }
        return ts.visitEachChild(node, visitor, ctx);
      }
      return ts.visitEachChild(sourceFile, visitor, ctx);
    };
  };
}
cevek commented 5 years ago

Unfortunately this is not possible, you cannot change checker diagnostic behaviour from transformers. You can only add new ones

anion155 commented 5 years ago

@cevek any way to disable error with specific code id?

anion155 commented 5 years ago

@cevek I mean, for whole project.