ts-morph#ConstructorDeclarationStructure TypeScript Examples
The following examples show how to use
ts-morph#ConstructorDeclarationStructure.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelsGenerator.ts From gengen with MIT License | 6 votes |
private getIdentities(identities: IIdentityModel[], interfaces: IInterfaceModel[]): StatementStructures[] {
return identities.map(
(z): ClassDeclarationStructure => ({
kind: StructureKind.Class,
isExported: true,
name: z.name,
ctors: [
{
parameters: [
{
name: z.property.name,
hasQuestionToken: true,
type: TypeSerializer.fromTypeName(`${z.property.type} | ${z.property.dtoType}`).toString()
}
] as OptionalKind<ParameterDeclarationStructure>[],
statements: `this.${z.property.name} = new ${z.property.type}(${z.property.name});`
}
] as OptionalKind<ConstructorDeclarationStructure>[],
properties: [{ scope: Scope.Public, name: z.property.name, type: z.property.type }, this.getGuardProperty(z.name)],
methods: [
{
scope: Scope.Public,
isStatic: true,
name: TO_DTO_METHOD,
parameters: [{ name: z.property.name, type: z.property.type }],
returnType: interfaces.find(
(i) =>
i.properties.length === 1 &&
i.properties.every((x) => x.dtoType === z.property.dtoType && x.name === z.property.name)
)?.name,
statements: `return { ${z.property.name}: ${z.property.name}.toString() };`
}
]
})
);
}
Example #2
Source File: AngularServicesGenerator.ts From gengen with MIT License | 5 votes |
protected getConstructorStatement(service: IServiceModel): ConstructorDeclarationStructure {
const superStatement = `super(${GET_BASE_PATH_FUNCTION_NAME}('${this.aliasResolver.alias}', '${service.relativePath}'), ${HTTP_CLIENT_VARIABLE_NAME});`;
return {
kind: StructureKind.Constructor,
parameters: [{ name: HTTP_CLIENT_VARIABLE_NAME, type: HTTP_CLIENT }],
statements: superStatement
};
}