Tslint: Fixing "property has no initializer and is not definitely assigned in the constructor" error causes incorrect member-access and whitespace lint errors

Created on 13 Feb 2018  路  7Comments  路  Source: palantir/tslint

Bug Report

  • __TSLint version__:5.9.1
  • __TypeScript version__:2.7.1
  • __Running TSLint via__: (pick one) Visual Studio Code

TypeScript code being linted

// code snippet
export abstract class Foo {
  public name!: string;

with tslint.json configuration:

{
  "defaultSeverity": "error",
  "extends": [
    "tslint:recommended"
  ],
}

Actual behavior

member-access and whitespace lint errors

Expected behavior

no lint errors

External Aged Away

Most helpful comment

pay attention to the file tsconfig.json, comment the ("strict": true) in the compilerOptions file

All 7 comments

@ramanujam-raman have you tried to restart VSCode after updating? It seem to have fixed the problem for me.

@reflectiondm, yes, I have restarted it since. I think the issue is really lack of support for Type Script 2.7.1. The latest update of Visual Studio Code pushes Type Script 2.7.1 as the default, and I needed to revert back to the older version of Type Script just to keep using tslint.

See the new language features in 2.7 here - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html

+1 I have same issue

restarting vscode worked for me

pay attention to the file tsconfig.json, comment the ("strict": true) in the compilerOptions file

class Engine {
constructor(public horsePower: number,
public engineType: string) { }
}

class Car {
private _engine: Engine;
constructor(engine: Engine) {
this.engine = engine;
}

get engine(): Engine {
    return this._engine;
}

set engine(engine: Engine) {
    if (engine === undefined) throw 'Supply Engine';
    this._engine = engine;
}

}

let engine = new Engine(1000, "awesome");
let car = new Car(engine);

console.log(car.engine.engineType);

Error: Property '_engine' has no initializer and is not definitely assigned in the constructor.
I can turn off the strict property but can't i use it without turning off the strict mode!

Seems like these issues were all around moving to newer TypeScript and TSLint versions.

Quick tip for anyone finding this thread: you can check which version of TypeScript you're using in VS Code with the "Select TypeScript Version" command. 馃槈

image

image

Was this page helpful?
0 / 5 - 0 ratings