Skip to content

Convert a TypeScript declare function with a body into a function. #12046

@sosukesuzuki

Description

@sosukesuzuki

Bug Report

  • I would like to work on a fix!

Current behavior

Convert a TypeScript declare function with a body into a function.

Try it out link

Output:

"use strict";

function foo() {}

Input Code

declare function foo() {}

Expected behavior

It should throw an error like tsc(TypeScript Playground). And it should support errorRecovery.

Also babel/parser should return a node of TSDeclareFunction instead of FunctionDeclaration(declare: true).

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  "presets": ["@babel/preset-typescript"]
}

Environment

I don't think environment information is needed because this issue is simple, but I will provide it if it is needed for you guys.

Possible Solution

Additional context

While working in Prettier, I notice that declare disappears. (Prettier Playground link)
It is possible to fix this issue on Prettier side, but I think this is the parser's responsibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has PRoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions