diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index d578c2b012cb..2631cb401e23 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -985,28 +985,27 @@ export class Converter { case SyntaxKind.VariableDeclaration: { const definite = !!node.exclamationToken; - const init = this.convertChild(node.initializer); - const id = this.convertBindingNameWithTypeAnnotation( - node.name, - node.type, - node, - ); + if (definite) { - if (init) { + if (node.initializer) { this.#throwError( node, 'Declarations with initializers cannot also have definite assignment assertions.', ); - } else if ( - id.type !== AST_NODE_TYPES.Identifier || - !id.typeAnnotation - ) { + } else if (node.name.kind !== SyntaxKind.Identifier || !node.type) { this.#throwError( node, 'Declarations with definite assignment assertions must also have type annotations.', ); } } + + const init = this.convertChild(node.initializer); + const id = this.convertBindingNameWithTypeAnnotation( + node.name, + node.type, + node, + ); return this.createNode(node, { type: AST_NODE_TYPES.VariableDeclarator, definite,