question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I properly include enums and interfaces in the project?

See original GitHub issue

Hi 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:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
JoA-MoScommented, Sep 17, 2018

I was getting the same error and adding const to my enum made the difference.

export const enum Statuses{
   Active = 'Active', 
   Deactivated = 'Deactivated',
   Undefined = ''
} 
2reactions
Tyler-Vcommented, Apr 30, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using enums as implementions for an interface, how ... - Medium
Create a class for each one and put them in an appropriately named package. Then create a factory class which would return you...
Read more >
Dealing with enums when interfaces are in separate project
I'd say that your basic data types (including enum s, interface s, and class es) should all be in one project. Thus, your...
Read more >
Where should I put my enums and interfaces?
I have an asp core MVC project for a college and I would like to implement a timetabling feature. To see if I...
Read more >
Quiz yourself: Enums and implementing interfaces in Java
This can be done by implementing the methods in the outer enum, or in every single instance, or a combination. As long as...
Read more >
How to implement an Interface using an Enum in Java
Enumerations serve the purpose of representing a group of named constants in a programming language. For example, the 4 suits in a deck...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found