打字稿代码样式TS2539:无法分配给' execFile'因为它不是变量

时间:2017-08-16 02:26:44

标签: javascript node.js typescript intellij-idea

我有一个代码

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.

我应该以正确的方式重写代码以解决这个问题,或者只是保持原状

1 个答案:

答案 0 :(得分:0)

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

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