I am writing a Yeoman generator and when I do it in JS like so:
"use strict";
var Generator = require("yeoman-generator");
var chalk = rquire("chalk");
module.exports = class extends Generator {
initializing() {
this.log(
chalk.bold(
"Welcome to the " + chalk.green("TypeScript for Serverless") + " generator!"
)
);
};
all is good. But I figured I could do this in TypeScript like so:
import Base = require("yeoman-generator");
import chalk from "chalk";
type IFileConfiguration = IComplexFileConfiguration | string;
export class Generator extends Base {
public options: IDictionary;
public initializing() {
this.log(
chalk.bold(
"Welcome to the " + chalk.green("TypeScript for Serverless") + " generator!"
)
);
}
My tsconfig.json is:
{
"compilerOptions": {
"declaration": true,
"module": "commonjs",
"lib": ["es2015", "es2016", "es2017", "esnext.asynciterable"],
"target": "es2015",
"moduleResolution": "node",
"sourceMap": false,
"noImplicitAny": true,
"outDir": "./generators/app",
"removeComments": true,
"experimentalDecorators": false,
"emitDecoratorMetadata": false
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*-spec.ts"]
}
But this creates a different module definition and one that completely breaks the Yeoman interface expectation. Is there a way for me to get the transpiled JS into the same export format as listed above?
Ok I figured it out. By defining the class without the export operator:
class Generator extends Base {}
I can then export at the end of the TS file like so:
export = Generator
Problem solved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With