【问题标题】:typescript code style TS2539:Cannot assign to 'execFile' because it is not a variable打字稿代码样式 TS2539:无法分配给“execFile”,因为它不是变量
【发布时间】:2017-08-16 11:04:14
【问题描述】:

我有密码

import * as path from 'path';
import * as globby from 'globby';
import { execFile } from 'child_process';
import * as util from 'util';
//import * as Promise from 'bluebird';
import * as fs from 'fs';

execFile = util.promisify(execFile);

当它编译成 js 时

像这样显示错误日志

Error:(12, 1) TS2539:Cannot assign to 'execFile' because it is not a variable.

我应该重写什么代码来以正确的方式解决这个问题,或者只是保持不变

【问题讨论】:

  • 导入绑定是不可变的,您不应该尝试修改它们。

标签: javascript node.js typescript intellij-idea


【解决方案1】:

compilerOptions 中为您的 tsconfig 设置types,像这样

"compilerOptions": {
    "target": "es5",
    "lib": [ "es2015"],
    "types": ["node"],
    "module": "commonjs"
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 2020-01-15
    • 2020-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多