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

Feature request: when a type parameter extends a type, it should be treated as that type #65

Open
rictic opened this issue Aug 5, 2020 · 1 comment

Comments

@rictic
Copy link
Collaborator

rictic commented Aug 5, 2020

Consider this code:

function foo<T extends string>(name: T) {
  return html`<input .value=${name}>`;
}

In the TS type system, name is assignable to a string, because it must be a subtype of string. Currently it looks like type parameters are treated as unknown

@rictic
Copy link
Collaborator Author

rictic commented Aug 5, 2020

Workaround:

function foo<T extends string>(name: T) {
  const nameStr: string = name;
  return html`<input .value=${nameStr}>`;
}

This leverages the TS type system to convert from T to string in a type safe way, so that by the time it reaches lit-analyzer, it's clearly a string.

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

No branches or pull requests

1 participant