I created an NPM package with a type defined (incl use):
(SolarEdge.js)
export type Period = 'DAY' | 'QUARTER_OF_AN_HOUR' | 'MONTH' | 'HOUR' | 'WEEK' | 'MONTH' | 'YEAR';
public getData = async (site: number, start: string, end: string, period: Period) => {}
(index.js)
export { default } from './SolarEdge';
After compiling from ts, I get 4 files (index.js, index.d.ts, SolarEdge.js, SolarEdge.d.ts)
When using this from my express app, it is complaining that I cant pass a string to this function, because it wants a Period.
Error: Argument of type 'string' is not assignable to parameter of type 'Period'.ts(2345)
Code:
const data = await solaredge.getData(
parseInt(req.params.site),
req.params.start,
req.params.end,
//'MONTH',
req.params.period,
);
req.params.period contains a string with 'MONTH' or something else. WHen using the hardcoded string MONTH it works, but using the req.params.period variable, it doesnt.
I tried doing: req.params.period as Period but the problem is: it cant find Period.
How does this work?
solaredge.Period, assuming that the type is being exported?