Skip to content

fix(59587): permit trailing commas in type parameter printing #59608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10013,7 +10013,7 @@ export const enum ListFormat {
SourceFileStatements = MultiLine | NoTrailingNewLine,
Decorators = MultiLine | Optional | SpaceAfterList,
TypeArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | AngleBrackets | Optional,
TypeParameters = CommaDelimited | SpaceBetweenSiblings | SingleLine | AngleBrackets | Optional,
TypeParameters = CommaDelimited | SpaceBetweenSiblings | SingleLine | AngleBrackets | Optional | AllowTrailingComma,
Parameters = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis,
IndexSignatureParameters = CommaDelimited | SpaceBetweenSiblings | SingleLine | Indented | SquareBrackets,
JSDocComment = MultiLine | AsteriskDelimited,
Expand Down
10 changes: 10 additions & 0 deletions src/testRunner/unittests/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ describe("unittests:: PrinterAPI", () => {
ts.ScriptKind.TSX,
));
});

printsCorrectly("typeParameters", {}, printer => {
return printer.printFile(ts.createSourceFile(
"source.tsx",
String.raw`export const id = <T,>(id: T): T => id;`,
ts.ScriptTarget.Latest,
/*setParentNodes*/ undefined,
ts.ScriptKind.TSX,
));
});
});

describe("No duplicate ref directives when emiting .d.ts->.d.ts", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8142,7 +8142,7 @@ declare namespace ts {
SourceFileStatements = 131073,
Decorators = 2146305,
TypeArguments = 53776,
TypeParameters = 53776,
TypeParameters = 53840,
Parameters = 2576,
IndexSignatureParameters = 8848,
JSDocComment = 33,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ function CustomSelect2(x) { }
//// [index.d.ts]
import { Props } from "react-select";
export declare const CustomSelect1: <Option>(x: Props<Option> & {}) => void;
export declare function CustomSelect2<Option>(x: Props<Option> & {}): void;
export declare function CustomSelect2<Option,>(x: Props<Option> & {}): void;
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ function b2(x) { return x; }
declare class A {
}
declare var a: <A>(x: A) => A;
declare function a2<A>(x: A): A;
declare function a2<A,>(x: A): A;
declare var a3: <A>(x: A) => globalThis.A;
declare function a4<A>(x: A): globalThis.A;
declare function a4<A,>(x: A): globalThis.A;
interface B {
}
declare var b: <B>(x: B) => B;
declare function b2<B>(x: B): B;
declare function b2<B,>(x: B): B;
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ type ToProvidedActor<TActors extends Record<string, UnknownActorLogic>> =
}>;

declare function setup<
>setup : <TActors extends Record<string, UnknownActorLogic> = {}>(implementations?: { actors?: { [K in keyof TActors]: TActors[K]; }; }) => { createMachine: <const TConfig extends MachineConfig<ToProvidedActor<TActors>>>(config: TConfig) => void; }
> : ^ ^^^^^^^^^ ^^^^^^^ ^^^ ^^^^^
>setup : <TActors extends Record<string, UnknownActorLogic> = {}>(implementations?: { actors?: { [K in keyof TActors]: TActors[K]; }; }) => { createMachine: <const TConfig extends MachineConfig<ToProvidedActor<TActors>>,>(config: TConfig) => void; }
> : ^ ^^^^^^^^^ ^^^^^^^ ^^^ ^^^^^

TActors extends Record<string, UnknownActorLogic> = {},
>(implementations?: {
Expand Down Expand Up @@ -129,8 +129,8 @@ setup({
> : ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^
>setup({ actors: { counter: counterLogic },}) : { createMachine: <const TConfig extends MachineConfig<{ src: "counter"; logic: ActorLogic<{ type: "INCREMENT"; }>; }>>(config: TConfig) => void; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^
>setup : <TActors extends Record<string, UnknownActorLogic> = {}>(implementations?: { actors?: { [K in keyof TActors]: TActors[K]; }; }) => { createMachine: <const TConfig extends MachineConfig<ToProvidedActor<TActors>>>(config: TConfig) => void; }
> : ^ ^^^^^^^^^ ^^^^^^^ ^^^ ^^^^^
>setup : <TActors extends Record<string, UnknownActorLogic> = {}>(implementations?: { actors?: { [K in keyof TActors]: TActors[K]; }; }) => { createMachine: <const TConfig extends MachineConfig<ToProvidedActor<TActors>>,>(config: TConfig) => void; }
> : ^ ^^^^^^^^^ ^^^^^^^ ^^^ ^^^^^
>{ actors: { counter: counterLogic },} : { actors: { counter: ActorLogic<{ type: "INCREMENT"; }>; }; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^

Expand Down Expand Up @@ -193,8 +193,8 @@ setup().createMachine({
> : ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
>setup() : { createMachine: <const TConfig extends MachineConfig<never>>(config: TConfig) => void; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^
>setup : <TActors extends Record<string, UnknownActorLogic> = {}>(implementations?: { actors?: { [K in keyof TActors]: TActors[K]; }; }) => { createMachine: <const TConfig extends MachineConfig<ToProvidedActor<TActors>>>(config: TConfig) => void; }
> : ^ ^^^^^^^^^ ^^^^^^^ ^^^ ^^^^^
>setup : <TActors extends Record<string, UnknownActorLogic> = {}>(implementations?: { actors?: { [K in keyof TActors]: TActors[K]; }; }) => { createMachine: <const TConfig extends MachineConfig<ToProvidedActor<TActors>>,>(config: TConfig) => void; }
> : ^ ^^^^^^^^^ ^^^^^^^ ^^^ ^^^^^
>createMachine : <const TConfig extends MachineConfig<never>>(config: TConfig) => void
> : ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
>{ entry: assign(() => ({})),} : { entry: AssignAction<never>; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const id = <T,>(id: T): T => id;