Skip to content

Feature: Auto inferred class properties #13068

@unional

Description

@unional

Don't know would this go against "type safety" in general.
I think with flow analysis this is now possible.

class Foo() {

  constructor() {
    this.a = 1  // automatically create property `private a: any` or `private a: number`
  }

  do() {
    this.b = this.a 
    // automatically create property `private b: any` or `private b: number | undefined`
    // because `do()` may not be called.
  }
  do2() {
    this.c = this.b 
    // automatically create proeprty `private c: any` or `private c: number | undefined`
    // because `do()` and `do2()` many not be called.
  }
}

EDIT: It's a pain to see allowJS works with Javascript like this but not within TypeScript. 🌷
EDIT2: add private
EDIT3: yay, my first "thumb-down", showing that I'm pushing the boundary. 🌷

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions