Tfjs: TypeScript compile error on 0.15.1

Created on 14 Feb 2019  路  7Comments  路  Source: tensorflow/tfjs

TensorFlow.js version

0.15.1

Browser version

Browser independent, since compilation already fails.

Describe the problem or feature request

Typescript throws an error, when importing tfjs.

node_modules/@tensorflow/tfjs-layers/dist/keras_format/types.d.ts:12:5 - error TS2411: Property 'config' of type 'T' is not assignable to string index type 'PyJsonValue'.

12     config: T;

Found 1 error.

Code to reproduce the bug / link to feature request

Console:

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();

Console:

tsc --init
tsc
bug

All 7 comments

cc @davidsoergel I think this can be solved by upgrading the version of typescript. Can you confirm?

Yes, that seems like the likely explanation. We use mapped types that are available starting in TS 2.9 (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html). tfjs-layers currently specifies TS 2.8.3, so I don't understand how things have been working for us. I'll investigate that out of curiosity, but in any case we need to bring all tfjs packages up to 2.9.2.

I found out that this has to do with the compiler options for TypeScript rather than the compiler version itself. The following flags prevent successful compilation:

"strictNullChecks": true

This is included in:

"strict": true

This flag is included in many tsconfig files, for example also in the default one generated by running:

tsc --init

Aha gotcha. Thanks for tracking that down. We don't use strictNullChecks in TFJS, but of course we also don't want to cause errors in dependent projects that do use it.

I'll continue looking into whether we can fix this case on our end. In the meantime, you can use the skipLibCheck compiler option to turn off the strict checking for dependencies, while leaving it on for your own code. (See https://stackoverflow.com/questions/40164034/typescript-strictnullchecks-with-limited-scope).

Just an FYI we probably won鈥檛 ever turn on strictNullChecks, it鈥檚 a huge change. We used to do this in old projects but it was more cumbersome than it was worth.

Ok, thank you for the information. Since this is the default config and many projects use it (e.g. Googles Polymer Starter Kit, which made me aware of it), it might be a good idea to include information about the need to include skipLibCheck in the documentation.

This is resolved here #287

Was this page helpful?
0 / 5 - 0 ratings