Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error with TypeScript 3.6 #2007

Closed
matt-tingen opened this issue Sep 9, 2019 · 7 comments · Fixed by #4109
Closed

Compile error with TypeScript 3.6 #2007

matt-tingen opened this issue Sep 9, 2019 · 7 comments · Fixed by #4109
Labels
comp:core type:support user support questions

Comments

@matt-tingen
Copy link

matt-tingen commented Sep 9, 2019

TensorFlow.js version

1.2.8

Browser version

node 12.6.0

Describe the problem or feature request

Packages using @tensorflow/tfjs-core fail to compile with TypeScript 3.6 because of a conflict between @types/[email protected] and the built-in webgl2 types added in TS 3.6.

node_modules/@types/webgl2/index.d.ts:582:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'WebGL2RenderingContext' must be of type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; readonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE: number; readonly ACTIVE_UNIFORMS: number; readonly ALIASED_LINE_WIDTH_RANGE: number; ... 554 more ...; readonly WAIT_FAILED: number; }', but here has type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; readonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE: number; readonly ACTIVE_UNIFORMS: number; readonly ALIASED_LINE_WIDTH_RANGE: number; ... 555 more ...; readonly MAX_CLIENT_WAIT_TIMEOUT_WEBGL: number; }'.

582 declare var WebGL2RenderingContext: {
                ~~~~~~~~~~~~~~~~~~~~~~

  node_modules/typescript/lib/lib.dom.d.ts:16450:13
    16450 declare var WebGL2RenderingContext: {
                      ~~~~~~~~~~~~~~~~~~~~~~
    'WebGL2RenderingContext' was also declared here.

This conflict was resolved in DefinitelyTyped/DefinitelyTyped#36837 which created @types/[email protected].
The only change is the removal of STENCIL_INDEX which does not appear to be used in this repo.

Updating to @types/[email protected] should allow projects with TS 3.6 to use @tensorflow/tfjs-core again.

Code to reproduce the bug / link to feature request

package.json

{
  "scripts": {
    "compile": "tsc"
  },
  "dependencies": {
    "@tensorflow/tfjs-core": "^1.2.8",
    "typescript": "^3.6.2"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "jsx": "preserve",
    "allowJs": true,
    "noEmit": true,
    "strict": true,
    "lib": ["dom", "esnext"]
  },
  "include": ["src"]
}

Create an empty src/index.ts and run yarn && yarn compile.

The fix can be confirmed with a resolution in the package.json:

  "resolutions": {
    "@types/webgl2": "0.0.5"
  }
@tafsiri
Copy link
Contributor

tafsiri commented Sep 9, 2019

Thanks for the info. FYI we usually suggest people add skipLibCheck to their tsconfig. https://www.tensorflow.org/js/tutorials/setup#typescript

@nise
Copy link

nise commented Sep 2, 2020

I run into the same issue with
"typescript": "^3.9.3" and "@tensorflow/tfjs": "^2.3.0".

If I set "skipLibCheck": true tfjs will not be found.

@aristotekean
Copy link

aristotekean commented Sep 27, 2020

npm i --save @types/webgl2
works for me

@JacobMuchow
Copy link

@kevinmalo 's solution worked for me as well

@jameshfisher
Copy link
Contributor

Why is this issue closed? The issue still exists, for the reason that @matt-tingen diagnosed over a year ago. The trivial PR that fixes it #2988 has also been open for many months ...

@jameshfisher
Copy link
Contributor

To clarify - @kevinmalo's solution is a workaround. At the time of writing, it installs @types/[email protected]. This is essentially the same workaround that @matt-tingen suggested originally. The correct fix is to fix the dependency upstream

@rthadur
Copy link
Contributor

rthadur commented Oct 21, 2020

cc @annxingyuan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:core type:support user support questions
Projects
None yet
7 participants