Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TSESTree.VariableDeclarator>(node, {
type: AST_NODE_TYPES.VariableDeclarator,
definite,
Expand Down