I'm currently exploring TypeScript for the first time and I find myself puzzled by the import/export mechanisms that differ from what I'm used to with ES6.
Here is an interface I'm attempting to export in a file named transformedRowInterface.ts
:
export interface TransformedRow {
id: number;
title: string;
summary: string;
body: string;
synopsis: string;
author: object;
impressions: number;
created: number;
updated: number;
}
And here is my attempt to import it in a file called newsArticleModel.ts
:
const appRoot = require("app-root-path");
import { TransformedRow } from "./transformedRowInterface";
// encountering the following error:
// [Node] /newsArticleModel.ts:2
// [Node] import { TransformedRow } from "./transformedRowInterface";
//SyntaxError: Unexpected token import
// also tried using require, which resulted in another error:
// const transformedRow = require(appRoot + "/src/controllers/transformedRowInterface.ts");
// triggering this error:
// [Node] (function (exports, require, module, __filename, __dirname) { export interface TransformedRow {
// [Node] ^^^^^^
// [Node]
// [Node] SyntaxError: Unexpected token export
This is my tsconfig:
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"noImplicitAny": false,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
// "*": ["node_modules/*", "src/types/*"]
}
},
"include": ["src/**/*"]
}
Can anyone spot what I might be doing incorrectly?