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

esm typings are weak or I have done something wrong #427

Open
kirevdokimov opened this issue May 1, 2021 · 1 comment
Open

esm typings are weak or I have done something wrong #427

kirevdokimov opened this issue May 1, 2021 · 1 comment

Comments

@kirevdokimov
Copy link

kirevdokimov commented May 1, 2021

TLDR

Types from npm run build-dts and esm build from npm run build-esm don't work together


Problem

Plain project, no bundlers, just Typescript 3.9.6 with "es6" target to compile.

I was going to use gl-matrix as a bundled dependency because of no bundler. I got esm dist from npm run build-esm then copy to my ./src/esm dir. Works just fine, but no types (like mat4.create() returns any instead of mat4 so I can't handle it with Typescript)

image

So I have made index.d.ts from npm run build-dts. Keeping this in root folder provides no types, for this reason I just copied this right to ./src/esm. But now I got

src/Cube.ts:7:22 - error TS2306: File '/mnt/c/Project/subtract-n-triangulate/src/esm/index.d.ts' is not a module.

7 import { mat4 } from "./esm/index.js";
                       ~~~~~~~~~~~~~~~~
Found 1 error.

For sure I can not an expert in typescript module declarations, but something looks wrong with all this. Would be happy to get some advice or solution. Thank you.

@kirevdokimov
Copy link
Author

Ok, got it.

First of all we declare our wrap module but never export it from index.d.ts:

// Wrap them in a "gl-matrix module"
typings = 'declare module "gl-matrix" {\n' + typings + "\n}";

image


// Honestly, this is just a horrible hack.


Second, even if we replace declare with export we still don't have types, because of module "gl-matrix" wrap. There is probably a reason for this to be here, but if I remove it, everything works just as I initially expect.

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

1 participant