In my current project, I am creating a class where I am directly accessing the package version number like this:
const pkg = require('../package.json')
export class MyClass() {
constructor() {
// Set the base version from package.json:
this.version = pkg.version
}
}
However, the Typescript compiler is giving me a friendly warning about using 'require' and suggesting to convert it to an import statement.
I wonder if it's possible to do so with a .json file?
What is considered the best practice for importing a package.json in a .ts file?