sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
80.02k stars 4.26k forks source link

Svelte reports incorrect types for the `buffered` binding on media elements #7342

Closed illright closed 2 weeks ago

illright commented 2 years ago

Describe the bug

When you bind to the buffered property of an <audio> element, for instance, the value that comes from this property has the type Array<{ start: number; end: number; }>. If you use that type on a bound variable, however, svelte-check will report its incompatibility with TimeRanges, which is what the type of this property should be.

<script lang="ts">
  let buffered: Array<{ start: number; end: number; }>;  // Type error!
</script>

<audio bind:buffered />
Opinion on these types In my opinion, this conversion from `TimeRanges` to a custom type is unjustified. Yes, `TimeRanges` is ridiculous, but it's standardized. Learning to operate this new type (the documentation of which is buried deep within the tutorial) is an unpleasant experience by itself. In this regard, I really like the approach of the Remix web framework that goes to great lengths to ensure _transferability of knowledge_. This type conversion is one of the few examples where knowledge of Svelte is not tranferable, and in my opinion it trumps the convenience of writing a `for .. of` loop instead of an index-based one.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-8p9wht?file=src/routes/index.svelte

Logs

Error: Type 'TimeRanges' is missing the following properties from type '{ start: number; end: number; }[]': pop, push, concat, join, and 28 more. (ts)

System Info

StackBlitz doesn't play well with `envinfo`, but it's a fresh install, so all the versions are the latest

Severity

annoyance

davidfrp commented 2 years ago

I too experience this same issue with the <video> element and its buffered property.

anito commented 1 year ago

Same here. It's easy to work around it, the extra line is yet annoying. I created this REPL https://svelte.dev/repl/38429f4787f04e6ea4ebf2246becd289?version=3.57.0

dummdidumm commented 2 weeks ago

This was fixed at some point.