gl-matrix
gl-matrix copied to clipboard
Missing type declarations for nested entrypoints
I've been importing from gl-matrix
with the following syntax:
import { determinant, getRotation } from 'gl-matrix/mat4';
import { length } from 'gl-matrix/vec3';
My code builds correctly (microbundle 0.13 + TypeScript 4.2.3) but the type declarations are not found, so the imports are implicitly typed "any":
Could not find a declaration file for module 'gl-matrix/mat4'.
'$PROJECT/node_modules/gl-matrix/cjs/mat4.js' implicitly has an 'any' type.ts(7016)
In a TypeScript project, this is easiest to spot with "noImplicitAny": true,
enabled in tsconfig.json
, because it becomes a compiler error. I found this issue in the process of converting a codebase to the TS "strict" mode.
Are these entrypoints a valid way of importing, and do you know if it's possible to provide type declarations for them? If I import from the root as import { mat4 } from 'gl-matrix'
then mat4.determinant
will have the correct type information, so certainly the type information exists, but is just not accessible when imported in the other way. Unfortunately I think the latter syntax defeats tree-shaking and will increase my library's bundle size, so I'd prefer to use the deeper entrypoints.
Thanks!
Hm. On https://www.npmjs.com/package/gl-matrix I see NPM claims the package has types from @types/gl-matrix
. But on https://www.npmjs.com/package/@types/gl-matrix I see "gl-matrix provides its own type definitions, so you do not need this installed.". Am I doing this wrong or is something out of date? 😰
Relevant: https://github.com/toji/gl-matrix/pull/390
For the time being I'm working around this by adding an additional *.d.ts
to my project:
declare module 'gl-matrix/vec4' {
import { vec4 } from 'gl-matrix';
export = vec4;
}
declare module 'gl-matrix/vec3' {
import { vec3 } from 'gl-matrix';
export = vec3;
}
declare module 'gl-matrix/vec2' {
import { vec2 } from 'gl-matrix';
export = vec2;
}
declare module 'gl-matrix/mat4' {
import { mat4 } from 'gl-matrix';
export = mat4;
}
declare module 'gl-matrix/mat3' {
import { mat3 } from 'gl-matrix';
export = mat3;
}