[read types and write types], [read type]
Many DOM APIs have setters that coerce values to strings. Using these APIs in perfectly valid ways will result in type warnings:
const input = document.createElement('input');
input.type = 'range';
input.max = 42; // Type '42' is not assignable to type 'string'.
These APIs could be more accurately described if getters and setters could have different types, like:
interface HTMLInputElement extends HTMLElement {
/**
* Defines the maximum acceptable value for an input element with type="number".When used with the min and step attributes, lets you control the range and increment (such as only even numbers) that the user can enter into an input field.
*/
get max(): string;
set max(v: any);
}
https://github.com/microsoft/TypeScript/issues/590
https://github.com/microsoft/TypeScript/issues/814
Use DOM APIs :)
Also see: https://github.com/runem/lit-analyzer/issues/43
Shown above
My suggestion meets these guidelines:
@DanielRosenwasser had mentioned this idea as an option for solving https://github.com/runem/lit-analyzer/issues/43
We're halfway there as of last Friday and we're looking into expanding it in 3.7. In 3.6 we should parse getters and setters on ambient class declarations, in 3.7 we intend to expand to object and interface types and include better checking rules for them.
(Although I don't think we have any backlog item for specifically differing getter/setter types yet)
I don't think it should be limited to properties.
We should consider if there's a way to work with divergent bounds on types. We usually think of a type being lower-bounded and upper-bounded by two types (Lower ≤ T ≤ Upper), but I don't know if we've thought much about T ≤ LesserUpper _and_ GreaterLower ≤ T.
Maybe that's just intersections of ranged types?
(Never ≤ T ≤ LesserUpper) & (GreaterLower ≤ T ≤ Unknown).
But that doesn't have any overlap, which is strange. Just spitballing here though.
Could we extend the duality to index access types?
Most helpful comment
We're halfway there as of last Friday and we're looking into expanding it in 3.7. In 3.6 we should parse getters and setters on ambient class declarations, in 3.7 we intend to expand to object and interface types and include better checking rules for them.