I would like to import properties from YAML field using this syntax:
import { DATABASE_HOST, DATABASE_PORT} from 'my-config.yml';
Behind the scenes I have code that would parse YML and pass correct values needed, so that part is not a problem.
However, I am not sure how to declare module in typings.d.ts to support this kind of syntax. I have tried it doing this way:
declare module '*.yml' {
const content: any;
export = content;
}
It would allow this syntax, which is not ideal:
import config from 'my-config.yml';
console.log(config.DATABASE_HOST);
Also tried this, however did not work as well:
declare module '*.yml' {
const content: any;
export = content;
}
Another thing I have tried, but this totally disabled type checking. I would like to at least be able to define config field type.
declare module '*.yml'
In ts config I have enabled both esModuleInterop and allowSyntheticDefaultImports.
I have mentioned that at top, but want to clarify again that I do not have problem with importing YAML into TS/JS context, problem is just with typing it out correctly.