Skip to content

import @typescript-eslint/typescript-estree 3.9.0 broken on TypeScript 3.9.7 #2388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brody4hire opened this issue Aug 12, 2020 · 5 comments · Fixed by #2405
Closed

import @typescript-eslint/typescript-estree 3.9.0 broken on TypeScript 3.9.7 #2388

brody4hire opened this issue Aug 12, 2020 · 5 comments · Fixed by #2405
Labels
bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@brody4hire
Copy link
Contributor

What:

There seems to be an issue when importing from @typescript-eslint/typescript-estree when using TypeScript 3.9.7.

I encountered this issue while working on typecheck for Prettier language-js code in prettier/prettier#8759, as described in this comment: prettier/prettier#8759 (comment)

I did notice that @typescript-eslint/typescript-estree is testing with typescript 4.0.0-beta. The issue goes away with typescript 4.0.0-beta, which is unfortunately not possible for us to use right now. I think this would evidently be a breaking change.

Repro

Here is the reproduction I made in my own work area:

package.json:

{
  "name": "typescript-eslint-test1",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "typescript": "^3.9.7"
  },
  "dependencies": {
    "@typescript-eslint/typescript-estree": "^3.9.0"
  }
}

a.ts:

import * as parser from "@typescript-eslint/typescript-estree";

Expected Result

Should build with no type error coming from sources in node_modules/@typescript-eslint/typescript-estree/dist

Actual Result

npx tsc --noEmit --target es2015 --module commonjs a.ts gave me the following output:

node_modules/@typescript-eslint/typescript-estree/dist/ts-estree/estree-to-ts-node-types.d.ts:112:45 - error TS2694: Namespace 'ts' has no exported member 'NamedTupleMember'.

112     [AST_NODE_TYPES.TSNamedTupleMember]: ts.NamedTupleMember;
                                                ~~~~~~~~~~~~~~~~

node_modules/@typescript-eslint/typescript-estree/dist/ts-estree/estree-to-ts-node-types.d.ts:120:55 - error TS2694: Namespace 'ts' has no exported member 'NamedTupleMember'.

120     [AST_NODE_TYPES.TSRestType]: ts.RestTypeNode | ts.NamedTupleMember;
                                                          ~~~~~~~~~~~~~~~~

node_modules/@typescript-eslint/typescript-estree/dist/ts-estree/ts-nodes.d.ts:3:918 - error TS2694: Namespace 'ts' has no exported member 'NamedTupleMember'.

3 export declare type TSNode = ts.Modifier | ts.Identifier | ts.QualifiedName | ts.ComputedPropertyName | ts.Decorator | ts.TypeParameterDeclaration | ts.CallSignatureDeclaration | ts.ConstructSignatureDeclaration | ts.VariableDeclaration | ts.VariableDeclarationList | ts.ParameterDeclaration | ts.BindingElement | ts.PropertySignature | ts.PropertyDeclaration | ts.PropertyAssignment | ts.ShorthandPropertyAssignment | ts.SpreadAssignment | ts.ObjectBindingPattern | ts.ArrayBindingPattern | ts.FunctionDeclaration | ts.MethodSignature | ts.MethodDeclaration | ts.ConstructorDeclaration | ts.SemicolonClassElement | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration | ts.IndexSignatureDeclaration | ts.KeywordTypeNode | ts.ImportTypeNode | ts.ThisTypeNode | ts.ConstructorTypeNode | ts.FunctionTypeNode | ts.TypeReferenceNode | ts.TypePredicateNode | ts.TypeQueryNode | ts.TypeLiteralNode | ts.ArrayTypeNode | ts.NamedTupleMember | ts.TupleTypeNode | ts.OptionalTypeNode | ts.RestTypeNode | ts.UnionTypeNode | ts.IntersectionTypeNode | ts.ConditionalTypeNode | ts.InferTypeNode | ts.ParenthesizedTypeNode | ts.TypeOperatorNode | ts.IndexedAccessTypeNode | ts.MappedTypeNode | ts.LiteralTypeNode | ts.StringLiteral | ts.OmittedExpression | ts.PartiallyEmittedExpression | ts.PrefixUnaryExpression | ts.PostfixUnaryExpression | ts.NullLiteral | ts.BooleanLiteral | ts.ThisExpression | ts.SuperExpression | ts.ImportExpression | ts.DeleteExpression | ts.TypeOfExpression | ts.VoidExpression | ts.AwaitExpression | ts.YieldExpression | ts.SyntheticExpression | ts.BinaryExpression | ts.ConditionalExpression | ts.FunctionExpression | ts.ArrowFunction | ts.RegularExpressionLiteral | ts.NoSubstitutionTemplateLiteral | ts.NumericLiteral | ts.BigIntLiteral | ts.TemplateHead | ts.TemplateMiddle | ts.TemplateTail | ts.TemplateExpression | ts.TemplateSpan | ts.ParenthesizedExpression | ts.ArrayLiteralExpression | ts.SpreadElement | ts.ObjectLiteralExpression | ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.CallExpression | ts.ExpressionWithTypeArguments | ts.NewExpression | ts.TaggedTemplateExpression | ts.AsExpression | ts.TypeAssertion | ts.NonNullExpression | ts.MetaProperty | ts.JsxElement | ts.JsxOpeningElement | ts.JsxSelfClosingElement | ts.JsxFragment | ts.JsxOpeningFragment | ts.JsxClosingFragment | ts.JsxAttribute | ts.JsxSpreadAttribute | ts.JsxClosingElement | ts.JsxExpression | ts.JsxText | ts.NotEmittedStatement | ts.CommaListExpression | ts.EmptyStatement | ts.DebuggerStatement | ts.MissingDeclaration | ts.Block | ts.VariableStatement | ts.ExpressionStatement | ts.IfStatement | ts.DoStatement | ts.WhileStatement | ts.ForStatement | ts.ForInStatement | ts.ForOfStatement | ts.BreakStatement | ts.ContinueStatement | ts.ReturnStatement | ts.WithStatement | ts.SwitchStatement | ts.CaseBlock | ts.CaseClause | ts.DefaultClause | ts.LabeledStatement | ts.ThrowStatement | ts.TryStatement | ts.CatchClause | ts.ClassDeclaration | ts.ClassExpression | ts.InterfaceDeclaration | ts.HeritageClause | ts.TypeAliasDeclaration | ts.EnumMember | ts.EnumDeclaration | ts.ModuleDeclaration | ts.ModuleBlock | ts.ImportEqualsDeclaration | ts.ExternalModuleReference | ts.ImportDeclaration | ts.ImportClause | ts.NamespaceImport | ts.NamespaceExportDeclaration | ts.ExportDeclaration | ts.NamedImports | ts.NamedExports | ts.ImportSpecifier | ts.ExportSpecifier | ts.ExportAssignment | ts.SourceFile | ts.Bundle | ts.InputFiles | ts.UnparsedSource | ts.JsonMinusNumericLiteral | ts.JSDoc | ts.JSDocTypeExpression | ts.JSDocUnknownTag | ts.JSDocAugmentsTag | ts.JSDocClassTag | ts.JSDocEnumTag | ts.JSDocThisTag | ts.JSDocTemplateTag | ts.JSDocReturnTag | ts.JSDocTypeTag | ts.JSDocTypedefTag | ts.JSDocCallbackTag | ts.JSDocSignature | ts.JSDocPropertyTag | ts.JSDocParameterTag | ts.JSDocTypeLiteral | ts.JSDocFunctionType | ts.JSDocAllType | ts.JSDocUnknownType | ts.JSDocNullableType | ts.JSDocNonNullableType | ts.JSDocOptionalType | ts.JSDocVariadicType | ts.JSDocAuthorTag;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ~~~~~~~~~~~~~~~~


Found 3 errors.

When I tried npm i --save-dev typescript@4.0.0-beta, then the same npx tsc command ran with no errors.

Additional Info

OS: macOS Catalina 10.15.6 (19G73)

Versions

package version
@typescript-eslint/typescript-estree 3.9.0
TypeScript 3.9.7
node v12.18.2
npm 6.14.5
@brody4hire brody4hire added package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for team members to take a look labels Aug 12, 2020
@bradzacher
Copy link
Member

Unfortunately this is one of the problems with moving forwards and supporting the latest version of TS.

I'm not sure if we can treat these types as a breaking change, or else we'll be forced to do a breaking change release with every new syntax TS releases, even though there have been no breaking functionality changes within the module itself - this would be quite a burden and slow the project down significantly - major bumps are big task.

You can augment the types for TS locally in your repo to silence these errors. Something like will probably do it?

import 'typescript';

declare module 'typescript' {
  type NamedTupleMember extends Node {}
}

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look labels Aug 12, 2020
brody4hire pushed a commit to brody4hire/prettier that referenced this issue Aug 12, 2020
@brody4hire
Copy link
Contributor Author

Hey I completely understand and can only imagine the stress of supporting the new TypeScript releases that have been coming out.

Unfortunately the code you gave me did not work 100% in my d.ts file. It first asked for a semicolon then was expecting a = sign. I was able to do this ugly and likely incorrect workaround hack to silence the errors:

import * as ts from 'typescript';
declare module 'typescript' {
  type NamedTupleMember = Node;
}

The good part is that it would give us errors when we upgrade to TypeScript 4.0.0, in which case we would simply remove the hack.

I would kinda like to see this pitfall documented somehow, though. Otherwise please feel free to close this one.

@bradzacher
Copy link
Member

Thinking about this - the only way for us to "fix" this is by duplicating the definition for the node type locally.

The type that consumes NamedTupleMember is required by other packages in the project, so we can't just not export it.

Happy to accept a PR if someone wants to clone the NamedTupleMember type here.

@bradzacher bradzacher added bug Something isn't working and removed awaiting response Issues waiting for a reply from the OP or another party labels Aug 12, 2020
@ExE-Boss
Copy link

ExE-Boss commented Aug 19, 2020

import 'typescript';

declare module 'typescript' {
  type NamedTupleMember extends Node {}
}

You need to do:

import "typescript";
declare module "typescript" {
	// Notice the `interface` keyword:
	export interface NamedTupleMember extends Node {}
}

Mine will work even with TypeScript 4.x thanks to interface merging.

@brody4hire
Copy link
Contributor Author

brody4hire commented Aug 19, 2020

	export interface NamedTupleMember extends Node {}

This change does seem to solve the issue with both TypeScript 3.9.7 and 4.0.0-beta when I tried it in prettier/prettier#8759. (I did encounter some other issues with prettier/prettier#8759 and TypeScript 4.0.0-beta, which I think are not relevant here.)

I will raise a PR next, hope it can be released in time to help with prettier/prettier#8759.

Thanks!


P.S. I had to change it like this to work with typescript-lint itself, did test it with both TS 3.9.7 & 4.0.0-beta in prettier/prettier#8759:

  export interface NamedTupleMember extends ts.Node {}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants