How do I properly include enums and interfaces in the project?
See original GitHub issueHi folks, I’m trying to build a library that is dependent on another public npm package of mine.
I am using the latest @angular/cli
that includes library generation.
In Project A, when built I have a enum/interfaces file that is in dist/a/lib/types.d.ts
that I want users to be able to freely import from the package.
Looks like this:
export interface ScrollIndex {
start?: number;
end?: number;
}
export interface ScrollEvent {
type: ScrollType;
index?: ScrollIndex;
scrollLeft?: number;
}
export enum ScrollType {
Horizontal,
Vertical
}
In another larger Project B, I have Project A listed as a dependency.
{
"name": "@.../ProjectB",
...
"dependencies": {
"@../ProjectA": "0.0.6",
}
}
Here’s where I may be confused or packing the project incorrectly.
Inside Project B, I am referencing Project A’s types using:
import { ScrollIndex, ScrollEvent, ScrollType } from '@.../ProjectA/lib/types';
I would like to be able to import them directly from @.../ProjectA
if possible.
Secondary to that issue, I then get an error when serving the project that it cannot resolve the types.
ERROR in ./node_modules/@ngx-easy/grid/esm5/ngx-easy-grid.js
Module not found: Error: Can't resolve '@ngx-easy/virtual-scroll/lib/types' in 'C:\Users\Tyler\Documents\GitHub\@ngx-easy\node_modules\@ngx-easy\grid\esm5'
When I view that esm5 generated file… I see only this is imported at the top… which is the only enum, coincidence?
import { ScrollType } from '@ngx-easy/virtual-scroll/lib/types';
If I remove that line from \node_modules\@ngx-easy\grid\esm5
then I no longer get console errors.
Any tips or feedback is much appreciated!
"@angular/compiler-cli": "^6.0.0-rc.1",
"@angular-devkit/build-ng-packagr": "~0.5.9",
"@angular-devkit/build-angular": "~0.5.9",
"ng-packagr": "^2.4.2",
"tsickle": ">=0.27.5",
"tslib": "^1.9.0",
"typescript": "2.7.2",
"@angular/cli": "~6.0.0-rc.6",
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
I was getting the same error and adding
const
to my enum made the difference.Hey thanks for the reply @alan-agius4
From
public_api.ts
export * from './lib/types';
I’ve have successfully been able to import…
import { ScrollIndex, ScrollEvent, ScrollType } from '@ngx-easy/virtual-scroll';
…and reference them in the typescript without issue, I’m not sure what I was doing before but the interfaces and enums appear to be working fine.