Я пишу Йоменский генератор, и когда я делаю это в JS, вот так:
"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!"
)
);
};
все хорошо. Но я подумал, что смогу сделать это в TypeScript так:
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!"
)
);
}
Мой tsconfig.json
:
{
"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"]
}
Но это создает другое определение модуля и такое, которое полностью нарушает ожидания интерфейса Yeoman. Могу ли я перевести переносимый JS в тот же формат экспорта, который указан выше?