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

Class that implements an interface does not get type inference on method arguments. #41399

Closed
nicksrandall opened this issue Nov 4, 2020 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@nicksrandall
Copy link

nicksrandall commented Nov 4, 2020

TypeScript Version: 4.0.5

Search Terms:
Class that implements an interface does not get type inference on method arguments.

Code

interface Component<A> {
  render(settings: A): string;
}

type HelloSettings = {
  greeting: string;
};

class GreetingComponent implements Component<HelloSettings> {
  render(settings) {
    return settings.greeting;
  }
}

Expected behavior:
I would expect the settings argument in render method of the "GreetingComponent" to have an inferred type of HelloSettings but currently that argument is inferred as any.

Actual behavior:
The settings argument in the render method of the "GreetingComponent" has an inferred type of any.

Playground Link:
https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgMIHsC2AHdILgA8AggHzIDeAUMslAQCbQAUAzhGGKAOasBcyYgEoBrMFB4BuKgF8qVMAE9sKABIQANhvQBlDlxC9kAXko1k3ehx6jxU2dKoINcVq2QBxKwe4YceAjBkYBwNCExA9z9cfCJ1LV19HlZyalp6ECYoNiTDViEzWnSOAFcoEGR2TmSAOksIa0NpWjkZIA

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 12, 2020
@RyanCavanaugh
Copy link
Member

See #10570 / #6118 / #1373 / others

@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