Skip to content

tfjs-layers - Model.build signature not matching Layer.build (typescript typecheck error) #347

@jeremychone

Description

@jeremychone

TensorFlow.js version

@tensorflow/tfjs-layers@0.6.2
file: https://github.com/tensorflow/tfjs-layers/blob/master/src/models.ts#L478

Browser version

N/A (node.js)

Describe the problem or feature request

Typescript type check error.
https://github.com/tensorflow/tfjs-layers/blob/master/src/models.ts#L478

Sequential.build(inputShape?: Shape): void incompatible with parent definition Layer.build(inputShape: Shape | Shape[]): void;

Should be
Sequential.build(inputShape?: Shape | Shape[]): void

Code to reproduce the bug / link to feature request

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


tf.setBackend('tensorflow');

Then run tsc (assuming tsconfig.json in the project, with strict = true)

and you get

node_modules/@tensorflow/tfjs-layers/dist/models.d.ts(28,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'.

From vscode:

The easiest way to see this error for end-user is to open the node_modules/@tensorflow/tfjs-layers/dist/models.d.ts in vscode
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions