ts-morph#ParameterDeclarationStructure TypeScript Examples

The following examples show how to use ts-morph#ParameterDeclarationStructure. 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 vote down vote up
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: AngularServicesMethodGenerator.ts    From gengen with MIT License 6 votes vote down vote up
protected getParameterStatement(
        parameter: IQueryParameter | IPathParameter | IBodyParameter
    ): OptionalKind<ParameterDeclarationStructure> {
        const statement: OptionalKind<ParameterDeclarationStructure> = {
            name: parameter.name,
            type: undefined,
            initializer: undefined
        };

        switch (parameter.place) {
            case ParameterPlace.Path:
                statement.type = this.getFullTypeName({
                    type: parameter.dtoType,
                    isModel: parameter.isModel,
                    isOptional: false
                });
                break;
            case ParameterPlace.Query:
                statement.type = this.getFullTypeName({
                    type: parameter.dtoType,
                    isModel: parameter.isModel,
                    isOptional: parameter.optional
                });
                statement.hasQuestionToken = parameter.optional;
                break;
            case ParameterPlace.Body:
                statement.type = this.getFullTypeName({
                    type: parameter.dtoType,
                    isCollection: parameter.isCollection,
                    isModel: parameter.isModel,
                    isOptional: parameter.optional
                });
                statement.hasQuestionToken = parameter.optional;
                break;
        }

        return statement;
    }