ts-simple-type icon indicating copy to clipboard operation
ts-simple-type copied to clipboard

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

Open rictic opened this issue 5 years ago • 1 comments

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 avatar Aug 05 '20 22:08 rictic

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.

rictic avatar Aug 05 '20 22:08 rictic