Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

allow use of typeof this.xxx (Error: Cannot find name this) #4793

Closed
xahon opened this issue Jul 11, 2019 · 2 comments
Closed

allow use of typeof this.xxx (Error: Cannot find name this) #4793

xahon opened this issue Jul 11, 2019 · 2 comments

Comments

@xahon
Copy link

xahon commented Jul 11, 2019

Bug Report

  • TSLint version: "tslint": "^5.18.0",
  • TypeScript version: "typescript": "3.5.3"
  • Running TSLint via: Rider/WebStorm

TypeScript code being linted

    // it works
    const { state } = (this)
    type inputsType = typeof state.form.inputs & { [s: string]: string }

    // it doesn't
    type inputsType = typeof this.state.form.inputs & { [s: string]: string }
                               ^ error here

image

I want do it for better typing when merging reducer states

{
    ...this.state,
    form: {
       ...this.state.form,
       inputs: Object
         .keys(this.state.form)
         .reduce((obj, key) => {
              obj[key] = ""
              return obj
           },
           { ...this.state.form.inputs } as any as inputsType, // here
         ),
    },
},

Actual behavior

error

Expected behavior

no error

@xahon xahon changed the title typeof this.xxx allow use of typeof this.xxx (Error: Cannot find name this) Jul 11, 2019
@JoshuaKGoldberg
Copy link
Contributor

@xahon it looks like your issue is with TypeScript, not TSLint. TypeScript is the programming language and compiler that's giving you a type error in your code. TSLint is a set of analysis that uses TypeScript.
You'll want to look for this issue on https://github.com/Microsoft/TypeScript/issues. Enjoy!

@xahon
Copy link
Author

xahon commented Jul 17, 2019

Ok, sorry, there is already the issue microsoft/TypeScript#1554

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants