For code examples, scroll below. First section contains the TypeScript
, second one the tsconfig.json
and package.json
. Using tsc (v2.1.6).
The question I have is how can I detect if typescript is picking up my tsconfig.json, see github repo where I'm runningot the issue: https://github.com/pluralsight-courses/typescript-fundamentals/tree/master/003-ClassesAndInterface.
When compiling commandline on with tsc - I get the error src/index.ts(17,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
- but in tsconfig I made sure it is targetting ES5 or up... I don't see what's going wrong/or what I am overlooking here.
TypeScript index.ts
class Engine {
constructor(public horsePower: number,
public engineType: string) {
}
}
class Car {
// Fields
private _engine: Engine;
// Constructor(s)
constructor(engine: Engine) {
this.engine = engine;
}
// Properties
get engine(): Engine { return this._engine; }
set engine(value: Engine) {
if (value == undefined) throw 'Supply an Engine!';
this._engine = value;
}
// Functions
start() { return `Started ${this.engine}.`; }
stop() { return `Stopped ${this.engine}.`; }
}
tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"sourceMap": true,
"outDir": "app"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
package.json
{
"name": "classesandinterfaces",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "npm run tsc && node app/index.js",
"tsc": "tsc --project ./tsconfig.json",
"tscver": "tsc --version"
},
"author": "",
"license": "ISC",
"devDependencies": {
"typescript": "2.1.6"
}
}