Skip to content

TS const type parameter is not serialized by generator #17215

@verytactical

Description

@verytactical

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

import * as t from "@babel/types";
import generate from "@babel/generator";
const param = t.tsTypeParameter(null, null, "T");

param.const = true; // HERE

const fn = t.arrowFunctionExpression([], t.blockStatement([]));
fn.typeParameters = t.tsTypeParameterDeclaration([
    param,
])

const p = t.file(t.program([
    t.variableDeclaration("const", [
        t.variableDeclarator(t.identifier("x"), fn)
    ])
]));

console.log(generate(p).code);

Configuration file name

No response

Configuration

{}

Current and expected behavior

Current:

const x = <T,>() => {};

Expected:

const x = <const T,>() => {};

Environment

@babel/generator: 7.26.5
OS: Linux 6.8
Node: 22.11.0 - node
Yarn: 1.22.22 - yarn
npm: 10.9.0 - npm

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: generator

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions