-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Closed
Labels
apiapi-finalizationinsiders-releasedPatch has been released in VS Code InsidersPatch has been released in VS Code Insidersverification-neededVerification of issue is requestedVerification of issue is requestedverifiedVerification succeededVerification succeeded
Milestone
Description
vscode.d.ts defines a few collection types: DiagnosticCollection, DataTransfer, EnvironmentVariableCollection, TestItemCollection. Currently we only expose a forEach method on each of these to iterate through them. This works but is annoying for a few reasons:
-
You can't use the with
for...ofloops -
forEachdoesn't play nicely with async/await. This is specifically an issue forDataTransferwhere you end up writing code such as:
const promises: Thenable<string>[] = [];
dataTransfer.forEach(x => {
promises.push(x.asString());
});
const result = Promise.all(promises);forEachuses a closure which messes up TS's type guards:
let thing: string | number = 1;
if (typeof thing === 'number') {
return;
}
dataTransfer.forEach(x => {
thing.charAt(0) // 💥 Thing is back to being a `string | number` again
});Potential fixes
Two potential approaches:
-
Add
.entries()function to these collections. These would behave likenew Map().entries() -
Make these types iterable directly by defining a
[Symbol.iterabor]function on them
Metadata
Metadata
Assignees
Labels
apiapi-finalizationinsiders-releasedPatch has been released in VS Code InsidersPatch has been released in VS Code Insidersverification-neededVerification of issue is requestedVerification of issue is requestedverifiedVerification succeededVerification succeeded