Compile error with TypeScript 3.6
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 https://github.com/DefinitelyTyped/DefinitelyTyped/pull/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"
}
Thanks for the info. FYI we usually suggest people add skipLibCheck to their tsconfig. https://www.tensorflow.org/js/tutorials/setup#typescript
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.
npm i --save @types/webgl2 works for me
@KevinMalo 's solution worked for me as well
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 https://github.com/tensorflow/tfjs/pull/2988 has also been open for many months ...
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
cc @annxingyuan