2

I have this on one file:

export module  Utils {
    export enum DataSources {
        SharepointList = "SharepointList",
        JsonData = "JsonData"
    };
}

and on another file I have this:

import CustomerDAO from "./ICustomerDAO";
import SharepointListDAOFactory from "./SharepointListDAOFactory";
import JsonDAOFactory from "./JsonDAOFactory";
import {Utils} from "./DatasourcesEnum";


export default abstract class DAOFactory{

    public static SHAREPOINTLIST: number = 1;
    public static REMOTEJSON : number = 2;

    public abstract getCustomerDAO(): CustomerDAO;

    public  static getDAOFactory(whichFactory: Utils.DataSources): DAOFactory {   
      switch (whichFactory) {
        case whichFactory.SharepointList: 
            return new SharepointListDAOFactory();
        case whichFactory.JsonData: 
            return new JsonDAOFactory();      
        default  : 
            return null;
      }
    }
}

But I get these errors:

Property 'SharepointList' does not exist on type 'DataSources'.
3
  • which version of tsc you're using? Commented Dec 20, 2017 at 22:40
  • I have 2.2....................... Commented Dec 20, 2017 at 22:42
  • the feature you attempt to use is available from 2.4 on Commented Dec 20, 2017 at 22:46

1 Answer 1

6

I'm not quite sure what the error you're getting means. It seems like you've made a mistake with your enum though. You're using the assigned value and not the enum itself in your switch statement.

public  static getDAOFactory(whichFactory: Utils.DataSources): DAOFactory {   
   switch (whichFactory) {
     case Utils.DataSources.SharepointList: 
       return new SharepointListDAOFactory();
     case Utils.DataSources.JsonData: 
       return new JsonDAOFactory();      
     default  : 
       return null;
   }
 }

The whichFactory identifier will have some value which is reflected in Utils.DataSources, and you'd want to compare the data to the enum itself. The value will not have the other datasources enum contained within itself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.