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'.
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'.
Share
Improve this question
asked Dec 20, 2017 at 22:39
Luis ValenciaLuis Valencia
34.1k99 gold badges311 silver badges532 bronze badges
3
- which version of tsc you're using? – OJ Kwon Commented Dec 20, 2017 at 22:40
- I have 2.2....................... – Luis Valencia Commented Dec 20, 2017 at 22:42
- the feature you attempt to use is available from 2.4 on – smnbbrv Commented Dec 20, 2017 at 22:46
1 Answer
Reset to default 6I'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 pare the data to the enum itself. The value will not have the other datasources enum contained within itself.