Skip to content

Method type parameters are dropped: read from the method node, while TSESTree carries them on the value function #173

Description

@zloirock
class A { m<T>(x: T): T { return x; } }

prints m(x: T): T - the <T> is gone. Same for object concise methods:

const o = { m<T>(x: T): T { return x; } };

prints m(x: T): T.

Root: the class-method printer reads node.typeParameters under an explicit
// @ts-expect-error 'typeParameters' lives on the method node, not its value - but TSESTree (the declared tree type) hangs them on the value FunctionExpression, so on conformant trees they are always dropped; the suppressed type error is the marker. The object-literal concise-method branch of Property consults neither node (it writes key( directly).

Adjacent shapes already fixed upstream: #114 (arrow type parameters), #92 (superTypeParameters).

Context: found by a parse -> print -> reparse structural gate over a ~8.5k-file TS/JS corpus while adopting esrap in core-js's build plugin, then re-verified in isolation. esrap 2.3.5; the ASTs below come from @typescript-eslint/typescript-estree 8.67 with loc/range enabled, so the repros are independent of our own (oxc-based) pipeline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions