Add --strictObjectIterables
(bikeshed): exclude primitive (string
) from Iterable
types
#59676
Open
6 tasks done
Labels
Needs Proposal
This issue needs a plan that clarifies the finer details of how it could be implemented.
Suggestion
An idea for TypeScript
π Search Terms
"iterable object", "string"
β Viability Checklist
β Suggestion
At the TC39 meeting in 2024-07, it was decided that
Iterable
expects objects.https://github.com/tc39/how-we-work/blob/main/normative-conventions.md#reject-primitives-in-iterable-taking-positions
To follow this decision, the
Iterable
andstring
types should be separated, and APIs that accept both types should be required to explicitly specifyIterable<any> | string
. Since this would be a breaking change, how about adding a new--strictObjectIterables
(bikeshed) option?In practice, the upcoming
ReadableStream.from
will acceptIterable<any>
andAsyncIterable<any>
, but will be restricted to objects. whatwg/streams#1310π Motivating Example
Enabling the
--strictObjectIterables
option raises a type error in the following example:π» Use Cases
What do you want to use this for?
Used for
ReadableStream.from
and other APIs to be added in the future.What shortcomings exist with current approaches?
Iterable
object andstring
are not distinguished by default.What workarounds are you using in the meantime?
Maybe
Iterable<any> & object
can rejectstring
.The text was updated successfully, but these errors were encountered: