Skip to content

ERROR TS2322: Type '~lib/object/Object' is not assignable to type 'module/A'. #2574

Closed
@jtenner

Description

@jtenner
class Nested {}

class A {
  b: Nested = new Nested();
  // `this` causes some kind of assignable error?
  c: Nested[] = [this.b];
}

export function add(): i32 {
  let a = new A();
  return 42;
}

It produces the following error...

;; ERROR TS2322: Type '~lib/object/Object' is not assignable to type 'module/A'.
;;    :
;;  7 │ c: Nested[] = [this.b];
;;    │                ~~~~
;;    └─ in module.ts(7,18)

I found this error while working on my HTTP parser and needed to do a big refactor. I hit nearly 280 errors because I had to port my lexer combinator rules over to class properties.

Is there a workaround? And where might the problem be located in the compiler? I would love to help.

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