-
Notifications
You must be signed in to change notification settings - Fork 725
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
Support TS in sub packages #390
base: master
Are you sure you want to change the base?
Conversation
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; ```
Maybe this the minimum cost plan for sub-packages type define.
|
I've been looking at this again and it seems that if Rollup implements this rollup/rollup#2201 (Object shape tree-shaking), we wouldn't need the sub packages for tree-shaking anymore. Is that correct? |
I didn't dig in this proposal. Can't say anything. |
I think this would be the relevant webpack issue webpack/webpack#8057 |
Hey, I just tried this in my project and it works great. Basically I just wanted this kind of imports to work well in typescript and this PR seems to do it just fine! import { fromTranslation } from 'gl-matrix/mat4'; I would love to help push this forward if it's possible, but am not sure what problems are preventing it from being merged. |
Good question! The main thing preventing me from merging is that I currently don't have enough time to sort out the issues. I'm rather preoccupied with other projects. |
I think there's an easier way to solve this, by appending a few extra lines to the existing type definitions: 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;
} ^I've been using those in a |
@donmccurdy Honestly, at this point, any solution that works would be super appreciated. So, a clear 👍 from my side. |
Hm, I tried putting that code (which works in a consuming project) into If we want to avoid those root-level files or directories, TypeScript may begin supporting package exports around v4.4, and this would provide more flexible, explicit mappings to each entrypoint. Perhaps waiting for v4.4 is the way to go.. |
Ref #389
Emitted all types to directory instead of single file.
This way each sub package can specify own "types" field.
Though there are problems
I solved by manual prepending import from types
this
between module names and types