workerd icon indicating copy to clipboard operation
workerd copied to clipboard

SqlStorageCursor.next type is not OK

Open mesterum opened this issue 7 months ago • 2 comments

https://github.com/cloudflare/workerd/blob/d7e9c38f6af8b6587ab23fd9c4635af522273ff1/src/workerd/api/sql.h#L212

Description

In this piece of code

let cursor = this.sql.exec(`SELECT seatId, occupant FROM seats`);
		
// Cursors are iterable.
let results = Iterator.from(cursor).map((row) => {
	// Each row is an object with a property for each column.
	return { seatNumber: row.seatId, occupant: row.occupant };
}).toArray();

row from map shows to may be undefined, but it shouldn't be

My solution

replace

 next(): { done?: false, value: T } | { done: true, value?: never }; 

with

 next(): IteratorResult<T, undefined>;

mesterum avatar Jul 30 '25 16:07 mesterum

This looks like a correct change, right @jasnell ?

petebacondarwin avatar Aug 05 '25 19:08 petebacondarwin

also experiencing this issue and the change seems to work. TS Playground with minimal repro

SnowSquire avatar Dec 09 '25 05:12 SnowSquire