I am currently testing a basic interface with the following code:
interface TestInterface {
id: number;
text: string;
}
const testInterfaceImplementation: TestInterface = {
id: 1,
text: 'sample text'
};
console.log(testInterfaceImplementation.text);
However, when I try to run this code using Node.js configuration, I encounter the following error message:
interface TestInterface {
^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
If I remove the interface from the code, it runs without any errors:
const testInterfaceImplementation = {
id: 1,
text: 'sample text'
};
console.log(testInterfaceImplementation.text);
What could be causing this issue? I have even attempted moving the interface to a separate .ts file, but the error persists.
This is my tsconfig.json file:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true
},
"exclude": [
"node_modules"
]
}