Skip to content

Commit

Permalink
feat: Add ability to add/insert type parameters with a default type n…
Browse files Browse the repository at this point in the history
…ode.
  • Loading branch information
dsherret committed Jun 9, 2018
1 parent 68fa2b1 commit cd05c3f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ export class TypeParameterDeclarationStructurePrinter extends FactoryStructurePr
writer.write(structure.name);
if (structure.constraint != null && structure.constraint.length > 0)
writer.write(` extends ${structure.constraint}`);
if (structure.default != null && structure.default.length > 0)
writer.write(` = ${structure.default}`);
}
}
1 change: 1 addition & 0 deletions src/structures/type/TypeParameterDeclarationStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

export interface TypeParameterDeclarationStructure extends NamedNodeStructure {
constraint?: string;
default?: string;
}
9 changes: 7 additions & 2 deletions src/tests/compiler/base/typeParameteredNodeTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,17 @@ describe(nameof(TypeParameteredNode), () => {
doTest("function identifier<T, U>() {}", 1, { name: "V", constraint: "string" }, "function identifier<T, V extends string, U>() {}");
});

it("should insert with default", () => {
doTest("function identifier<T, U>() {}", 1, { name: "V", default: "string" }, "function identifier<T, V = string, U>() {}");
});

it("should insert all the properties of the structure", () => {
const structure: MakeRequired<TypeParameterDeclarationStructure> = {
name: "V",
constraint: "string"
constraint: "string",
default: "number"
};
doTest("function identifier() {}", 0, structure, "function identifier<V extends string>() {}");
doTest("function identifier() {}", 0, structure, "function identifier<V extends string = number>() {}");
});
});

Expand Down

0 comments on commit cd05c3f

Please sign in to comment.