Skip to content

Type 'Scope' is not assignable to type 'this' #8164

Closed
@yortus

Description

@yortus

TypeScript Version:

1.9.0-dev.20160419
1.8.7

Code

class Scope {

    constructor(private locals: string[], private parent: Scope) {
    }

    find(name: string) {
        var scope = this;
        while (scope && scope.locals.indexOf(name) === -1) {
            scope = scope.parent; // ERROR: Type 'Scope' is not assignable to type 'this'
        }
        return scope;
    }
}


let outer = new Scope(['a', 'b'], null);
let inner = new Scope(['b', 'c'], outer);
assert(inner.find('a') === outer);
assert(inner.find('b') === inner);
assert(inner.find('d') === null);

Expected behavior:

  • compile time: no compile errors
  • runtime: all assertions pass.

Actual behavior:

  • compile time: compile error as shown in code comment.
  • runtime: all assertions pass as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadQuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions