【问题标题】:TFJS throws TS2411 as error when importing using TypescriptTFJS 使用 Typescript 导入时抛出 TS2411 错误
【发布时间】:2019-07-07 14:28:28
【问题描述】:

我尝试在 Typescript 环境中导入 tfjs。但是,我收到以下错误:

node_modules/@tensorflow/tfjs-layers/dist/keras_format/types.d.ts:12:5 - 错误 TS2411:“T”类型的属性“config”不可分配给字符串索引类型“PyJsonValue”。

这可以通过以下步骤轻松重现:

npm init
npm i @tensorflow/tfjs
npm i typescript

创建一个 index.ts:

import * as tf from '@tensorflow/tfjs';

// Define a model for linear regression.
const model = tf.sequential();

配置和编译:

tsc --init
tsc

package.json 然后包含以下内容:

"dependencies": {
  "@tensorflow/tfjs": "^0.15.1",
  "typescript": "3.3.3"
}

tsconfig 看起来像这样:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",                     
    "strict": true,                           
    "esModuleInterop": true                   
  }
}

【问题讨论】:

    标签: typescript tensorflow.js


    【解决方案1】:

    在与 tfjs 团队进行了一些互动后,我们可以追查到问题所在。问题确实出在打字稿配置中。 如果设置了标志:"strictNullChecks": true,typescript 会抛出上述编译错误。由于此标志包含在"strict": true 中,而"strict": true 又包含在默认的打字稿配置中,因此这是不受欢迎的行为。

    作为一种临时解决方法,可以使用skipLibCheck 只检查他们自己的代码而不是依赖项。

    可以在这里找到与此相关的问题:Issue on tfjs

    【讨论】:

      猜你喜欢
      • 2020-08-28
      • 2016-02-22
      • 2022-08-18
      • 2017-12-17
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 1970-01-01
      • 2015-07-19
      相关资源
      最近更新 更多