Skip to content

Error using non-null-assertion on a method with a this parameter (regression) #23040

Description

I hit a regression trying to upgrade to the latest version.

TypeScript Version: Tested with 2.8.1 and 2.9.0-dev.20180330

Search Terms:

  • non null assertion
  • The 'this' context of type 'void'

Code

interface Foo {
    required: ((this: Foo) => void);
    optional: ((this: Foo) => void) | null;
}

declare const foo: Foo;
foo.required();
foo.optional!();

Expected behavior:

Successful compilation

Actual behavior:

Error on the last line:

The 'this' context of type 'void' is not assignable to method's 'this' of type 'HTMLElement'.

Playground Link:

https://www.typescriptlang.org/play/index.html#src=interface%20Foo%20%7B%0D%0A%20%20%20%20required%3A%20((this%3A%20Foo)%20%3D>%20void)%3B%0D%0A%20%20%20%20optional%3A%20((this%3A%20Foo)%20%3D>%20void)%20%7C%20null%3B%0D%0A%7D%0D%0A%0D%0Adeclare%20const%20foo%3A%20Foo%3B%0D%0Afoo.required()%3B%0D%0Afoo.optional!()%3B

Related Issues:

N/A

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions