+-- @tensorflow/[email protected]
| +-- @tensorflow/[email protected]
| | `-- [email protected]
| `-- @tensorflow/[email protected]
`-- [email protected]
N/A
Cannot import @tensorflow/tfjs from TypeScript.
import * as tf from "@tensorflow/tfjs"
node_modules/@tensorflow/tfjs-layers/dist/models.d.ts:27:5 - error TS2416: Property 'build' in type 'Sequential' is not assignable to the same property in base type 'Model'.
Type '(inputShape?: number[] | undefined) => void' is not assignable to type '(inputShape: number[] | number[][]) => void'.
Types of parameters 'inputShape' and 'inputShape' are incompatible.
Type 'number[] | number[][]' is not assignable to type 'number[] | undefined'.
Type 'number[][]' is not assignable to type 'number[] | undefined'.
Type 'number[][]' is not assignable to type 'number[]'.
Type 'number[]' is not assignable to type 'number'.
27 build(inputShape?: Shape): void;
~~~~~
Hi Toru,
I think the tsconfig settings are off. I cloned your repo and transplanted
our tsconfig and it built:
https://github.com/tensorflow/tfjs-core/blob/master/tsconfig.json
On Tue, Apr 24, 2018 at 4:49 AM, Toru Nagashima notifications@github.com
wrote:
TensorFlow.js version
+-- @tensorflow/[email protected]
| +-- @tensorflow/[email protected]
| |-- [email protected] |-- @tensorflow/[email protected]
`-- [email protected]Browser version
N/A
Describe the problem or feature requestCannot import @tensorflow/tfjs from TypeScript.
import * as tf from "@tensorflow/tfjs"
node_modules/@tensorflow/tfjs-layers/dist/models.d.ts:27:5 - error TS2416: Property 'build' in type 'Sequential' is not assignable to the same property in base type 'Model'.
Type '(inputShape?: number[] | undefined) => void' is not assignable to type '(inputShape: number[] | number[][]) => void'.
Types of parameters 'inputShape' and 'inputShape' are incompatible.
Type 'number[] | number[][]' is not assignable to type 'number[] | undefined'.
Type 'number[][]' is not assignable to type 'number[] | undefined'.
Type 'number[][]' is not assignable to type 'number[]'.
Type 'number[]' is not assignable to type 'number'.27 build(inputShape?: Shape): void;
~Code to reproduce the bug / link to feature request
https://github.com/mysticatea/tfjs-issue-ts
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/tensorflow/tfjs/issues/226, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABDLze8zsgPQBvWXQ2n1Qw8k-kHOaD1Uks5truckgaJpZM4ThQTc
.
I found the compile error happens if I enabled "strictNullChecks": true build option.
The "strictNullChecks": true option is very useful option to prevent null dereference errors.
It's very inconvenient if I cannot use the option in all software that uses tensorflow.js.
The error occurs because Sequential is not a valid subclass of Layer. Sequential.build: (inputShape?: Shape | undefined): void but Layer.build: (inputShape: Shape | Shape[]).
The easiest fix is to make both inputShape parameters either optional or non-optional. I'm not sure which is correct.
Note that this fix is still not sound but Typescript doesn't enforce soundness in inheritance.
I think the inconsistency in the signature of Sequential.build() and
Model.build() is an oversight. I sent out a PR to fix that:
https://github.com/tensorflow/tfjs-layers/pull/215
On Sat, May 26, 2018 at 7:56 PM Nathan Shively-Sanders <
[email protected]> wrote:
The error occurs because Sequential is not a valid subclass of Model. Sequential.build:
(inputShape?: Shape | undefined): void but Model.build: (inputShape:
Shape | Shape[]).The easiest fix is to make both inputShape parameters either optional or
non-optional. I'm not sure which is correct.Note that this fix is still not sound but Typescript doesn't enforce
soundness in inheritance.—
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
https://github.com/tensorflow/tfjs/issues/226#issuecomment-392295381,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQC5fvNniisdmmvcyU3h79nGMd0NWHJlks5t2euXgaJpZM4ThQTc
.
Shanqing Cai
Software Engineer
Google
[email protected]
Does it makes sence if we enable the strictNullChecks option in the tfjs projects?
@mysticatea It's more important that users with projects that have strictNullChecks can import tfjs without problems, which is what @caisq's PR does.
I flipped on strict in tfjs-layers and got 634 errors. tfjs-core had 459. So it's a lot of work.
@sandersn
It's more important that users with projects that have strictNullChecks can import tfjs without problems
I agree. I did not intend enabling all strict options. My intention was that we should enable strictNullChecks option in tfjs repositories in order to avoid regression bug of this issue. The check the regression bug is difficult to humans.
See https://stackoverflow.com/questions/40164034/typescript-strictnullchecks-with-limited-scope
In your project use the skipLibCheck option added in Typescript 2.0 to skip checking the *.d.ts files of your dependencies. This will also speed up compilation.
Most helpful comment
I found the compile error happens if I enabled
"strictNullChecks": truebuild option.The
"strictNullChecks": trueoption is very useful option to prevent null dereference errors.It's very inconvenient if I cannot use the option in all software that uses tensorflow.js.