Skip to content

Importing interface from a file with an enum (or a class) #126

@dballesteros7

Description

@dballesteros7

Consider the following files:

types.ts

export interface ITokenStorageService {
  getToken():string;
  setToken(token:string):void;
}

export const enum LoginState {
  LogginIn, LoggedIn, NotLoggedIn
}

token.ts

import {ITokenStorageService} from './types';

export default class TokenStorageService implements ITokenStorageService {

  private userToken:string;

   getToken():string {
    return this.userToken;
  }

  setToken(token:string) {
    this.userToken = token;
  }
}

When compiling this on the browser, the following error appears:

importerModule.setters[importerIndex] is not a function

I traced it to https://github.com/systemjs/systemjs/blob/master/lib/register.js#L287.

The problem is that the transpiled token.js file has no setters but the types file is registered as a dependency of the token module. I think this has to do with JSPM and how it registers the imports even if typescript doesn't register the dependency at runtime?

For now I just added a bandaid fix:

if (importerIndex < importerModule.setters.length) {
  importerModule.setters[importerIndex](exports);
}

Any ideas? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions