Skip to content

ThisType cant work in the block scope of functionΒ #52849

Closed

Description

Bug Report

πŸ”Ž Search Terms

ThisType

πŸ•— Version & Regression Information

  • This is a crash
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about ThisType

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function defineComp<Bar, Data>(
  options: {
    bar: Bar,
    foo: () => Data
  } & ThisType<{ bar: Bar }>
): Bar
function defineComp(options: any) {
  return options.bar
}

// failed
const aaa = defineComp({
  foo() {
    console.log(this.bar) // no error
    return {
      count: this.bar() // throw error
    }
  },
  bar() {
    return '1'
  },
})

// work
const bbb = defineComp({
  bar() {
    return '1'
  },
  foo() {
    console.log(this.bar)
    return {
      count: this.bar() // it's work
    }
  },
})

πŸ™ Actual behavior

TS error: (property) bar: unknown in aaa

πŸ™‚ Expected behavior

no error

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

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions