Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not refer a type to this (in strict mode) #16016

Closed
k8w opened this issue May 23, 2017 · 1 comment
Closed

Can not refer a type to this (in strict mode) #16016

k8w opened this issue May 23, 2017 · 1 comment
Labels
Question An issue which isn't directly actionable in code

Comments

@k8w
Copy link

k8w commented May 23, 2017

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)
2.3.3

Code

strict is true

function test(){
    console.log(this.value);
    console.log((this as any).value);
}

let a = {
    value: 'a',
    test: test
}

a.test()

Expected behavior:
succ

Actual behavior:

Test.ts(2,17): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
Test.ts(3,18): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.

@mhegazy
Copy link
Contributor

mhegazy commented May 23, 2017

Either specify a this type in your function declatation:

function test(this: any) {
    console.log(this.value);
}

or switch of --noImplicitThis false

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label May 23, 2017
@k8w k8w closed this as completed May 24, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

2 participants