Skip to content

Regression: ERROR TS2564: Property 'module/A#c' has no initializer and is not assigned in the constructor before 'this' is used or returned. #2576

Open
@jtenner

Description

@jtenner

Link: here

Minimal reproduction: (as far as I can reduce it)

class B {}
class A {
  b: B;
  c: B;
  constructor() {
    // this should be safe?
    this.b = new B();
    this.c = this.b;
  }

}

export function fib(n: i32): i32 {
  let a = new A();
  return 0;
}
Error:
;; ERROR TS2564: Property 'module/A#c' has no initializer and is not assigned in the constructor before 'this' is used or returned.
;;    :
;;  4 │ c: B;
;;    │ ~
;;    └─ in module.ts(4,3)
;;    :
;;  7 │ this.c = this.b;
;;    │          ~~~~~~
;;    └─ in module.ts(7,14)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions