Skip to content

Cannot reference an object within one of its methods' default arguments #11628

@fabiospampinato

Description

@fabiospampinato

TypeScript Version: 2.0.3

Code

let Obj = {
  get () {},
  set ( value = Obj.get () ) {}
};

Obj.missing (); // Obj is treated as `any`, so I don't get any error for the usage of the undefined method `missing`

Expected behavior:

I expect to get an error for the usage of the undefined method Obj.missing.

Actual behavior:

I don't get any, since if I use Obj within a default argument inside one of Obj's own methods the entire object type becomes any.

Ugly workaround:

let _self;
let Obj = _self = {
  get () {},
  set ( value = _self.get () ) {}
};

Obj.missing (); // I get an error as expected

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions