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

Missing type declarations for nested entrypoints #423

Open
donmccurdy opened this issue Apr 2, 2021 · 3 comments
Open

Missing type declarations for nested entrypoints #423

donmccurdy opened this issue Apr 2, 2021 · 3 comments

Comments

@donmccurdy
Copy link

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!

@donmccurdy
Copy link
Author

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? 😰

@stefnotch
Copy link
Collaborator

Relevant: #390

@donmccurdy
Copy link
Author

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants