Tengo una clase Helper con una función getInfo definida así...
// Helper package function Helper() { this.loaded = true; ..... } Helper.prototype.getInfo = function(id) { if (!this.loaded) { loadData.apply(this) } ..... };Importé el paquete Helper y lo uso así
import {getInfo} from "helper" ... const CONFIG: Config[] = [ {name: "foo", info: [getInfo("foo")]}, {name: "bar", info: [getInfo("bar")]}, ] ...En v3.6.5, fue compilado así...
const helper_1 = require("helper"); ... const CONFIG: Config[] = [ {name: "foo", info: [helper_1.getInfo("foo")]}, {name: "bar", info: [helper_1.getInfo("bar")]}, ] ...En v4.x, fue compilado así...
const helper_1 = require("helper"); ... const CONFIG: Config[] = [ {name: "foo", info: [(0,helper_1.getInfo)("foo")]}, {name: "bar", info: [(0,helper_1.getInfo)("bar")]}, ] ... Como está usando un separador de coma, obtuve un this undefined .
Aquí está mi tsconfig:
{ "compilerOptions": { "target":"ES2018", "module": "commonjs", "lib": ["esnext", "es2016", "es2017.object", "es2017.string"], "declaration": true, "outDir": "./dist/lib", "declarationDir": "./dist/types", "strict": true, "noImplicitAny": true, "strictNullChecks": true, "noImplicitThis": true, "alwaysStrict": true, "noUnusedLocals": false, "noUnusedParameters": false, "noImplicitReturns": true, "noFallthroughCasesInSwitch": false, "inlineSourceMap": true, "inlineSources": true, "experimentalDecorators": true, "strictPropertyInitialization":false, "typeRoots": ["./node_modules/@types"] }, "exclude": ["build","node_modules", "dist"] }¿Cómo evito que TypeScript se compile usando el operador de coma?