-
Notifications
You must be signed in to change notification settings - Fork 725
The type define can't be derived correctly #389
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
Comments
I'm always open to suggestions or PRs regarding improving gl-matrix! |
I will send the pr today, a lot of diff, but compatibility will be guaranteed. |
Generate .d.ts file for each sub-package. But now I do not know how to generate sub-package d.ts file~
Rewrite with ts. then generate the sub-packages. I think Plan2 is better, what's your opinion? @stefnotch |
So, basically, I added the type definitions for my main use case which is simply importing everything from "gl-matrix". I didn't take the subpackages into account, as that seemed a fair bit more complex. import { vec3 } from "gl-matrix"; @TrySound Sorry for the ping, but I thought that you might be an expert on this topic. A quite relevant question here is, do we still need all the subpackages? |
Yes, unless you choose unique name for each function.
https://unpkg.com/browse/[email protected]/esm/
@stefnotch Doesn't this syntax assume sub packages? Or is this something like old school namespace?
|
Ref toji#389 Emitted all types to directory instead of single file. This way each sub package can specify own "types" field. Though there are problems - tsc do not emit types imports in dts files I solved by manual prepending import from types ``` import { mat2, mat2d, mat3, mat4, quat, quat2, vec2, vec3, vec4, ReadonlyMat2, ReadonlyMat2d, ReadonlyMat3, ReadonlyMat4, ReadonlyQuat, ReadonlyQuat2, ReadonlyVec2, ReadonlyVec3, ReadonlyVec4 } from './types'; /** * Quaternion * @module quat */ /** * Creates a new identity quat * * @returns {quat} a new quaternion */ export function create(): quat; ``` - tsc do not resolve reused function from another module so we end with this ``` export const fromValues: typeof vec4.fromValues; // 2693: 'vec4' only refers to a type, but is being used as a value here. ``` - even if we write all imports from another module we have a conflict between module names and types ``` import { ..., vec2, ... } from './types'; export const fromValues: typeof vec4.fromValues; ```
Ref toji#389 Emitted all types to directory instead of single file. This way each sub package can specify own "types" field. Though there are problems - tsc do not emit types imports in dts files I solved by manual prepending import from types ``` import { mat2, mat2d, mat3, mat4, quat, quat2, vec2, vec3, vec4, ReadonlyMat2, ReadonlyMat2d, ReadonlyMat3, ReadonlyMat4, ReadonlyQuat, ReadonlyQuat2, ReadonlyVec2, ReadonlyVec3, ReadonlyVec4 } from './types'; /** * Quaternion * @module quat */ /** * Creates a new identity quat * * @returns {quat} a new quaternion */ export function create(): quat; ``` - tsc do not resolve reused function from another module so we end with this ``` export const fromValues: typeof vec4.fromValues; // 2693: 'vec4' only refers to a type, but is being used as a value here. ``` - even if we write all imports from another module we have a conflict between module names and types ``` import { ..., vec2, ... } from './types'; export const fromValues: typeof vec4.fromValues; ```
See here. Not solved yet. Need assistance. |
I took a look at it and am not sure how to solve those issues. Maybe @hustcc has some ideas? |
Code below:
In addition, the source code structure is different from npm package, this is not a best practice maybe. We have many ways to organize code for code split, But the way now is not very good.
Do you need a pr?
The text was updated successfully, but these errors were encountered: