While working on my Yeoman generator, I initially wrote it in JavaScript like this:
"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!"
)
);
};
Everything was fine with the JS version. However, I decided to switch to TypeScript and rewrote the code as follows:
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
looks like this:
{
"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"]
}
However, using TypeScript resulted in a different module definition that caused issues with the Yeoman interface. Is there a way for me to transpile the TypeScript code into the same export format as the original JS version?