Skip to content

fix: print class type parameters#144

Closed
jycouet wants to merge 1 commit into
sveltejs:mainfrom
jycouet:fix/class-type-parameters
Closed

fix: print class type parameters#144
jycouet wants to merge 1 commit into
sveltejs:mainfrom
jycouet:fix/class-type-parameters

Conversation

@jycouet

@jycouet jycouet commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

The TS ClassDeclaration/ClassExpression printer never visits node.typeParameters, so a generic class class Foo<T> {} round-trips to class Foo {} (the <T> is silently lost). superTypeParameters on extends were handled, but the class's own type parameters were missing.

if (node.id) {
	context.visit(node.id);
}

if (node.typeParameters) {
	context.visit(node.typeParameters); // added
}

if (node.id || node.typeParameters) {
	context.write(' ');
}

Found while migrating Svelte code via sveltejs/cli, where reserializing untouched classes stripped generics.

Includes a test and a changeset.

@changeset-bot

changeset-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cecd914

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
esrap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jycouet jycouet closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant