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

Method parameter types missing in class property initializer in extended class #41324

Closed
puckey opened this issue Oct 29, 2020 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@puckey
Copy link

puckey commented Oct 29, 2020

TypeScript Version: Nightly (v4.1.0-dev.20201029)

Search Terms:
extended class property initializer
extended class property function

Code

class A {
  declare test: (foo: string) => string
}

class B extends A {
  test = bar => bar
}

or

class A {
  test = (foo: string) => foo
}

class B extends A {
  test = bar => bar
}

Expected behavior:
In class B the bar parameter should be inferred as string

Actual behavior:
Parameter 'bar' implicitly has an 'any' type.

Playground Link:
https://www.typescriptlang.org/play?ts=4.1.0-dev.20201029#code/MYGwhgzhAECC0G8CwAoa0AuBTCHoF5oAKAMwHsyAuaXAJwEsA7AcwEoCA+acs1AX1SpQkGACFoWAB7ZGAExjxkaaMDKM6AV2AYytIuyXp0EDQAcse1qiOYAFvQgA6bLgLcKnd72UCUvoA

Related Issues:
Not that I could find

This does work:

class A {
  test = (foo: string) => foo
}

class B extends A {
  constructor() {
    super()
    this.test = bar => bar
  }
}
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 10, 2020
@RyanCavanaugh
Copy link
Member

See #10570

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants