Repository navigation
Description
Summary
@tsrx/core 0.3.0 changes how the shared type-only transform lowers a @for body that contains an await (tsrx-org/tsrx#212). It emits await __map_iterable_async(…) and imports the helper from the platform's forOfIterableHelper. Octane sets that to octane/tsrx-iterable, which re-exports only map_iterable. That subpath should also re-export map_iterable_async when Octane moves to @tsrx/core 0.3.
This affects only the editor's virtual TSX. Octane's runtime compiler never imports octane/tsrx-iterable, and it rejects async components anyway.
What happens without the export
export async function rows(items: number[]) @{
@for (const item of items) {
<li>{await Promise.resolve(item)}</li>
}
}
With core 0.3.0 and Octane's platform descriptor, the virtual TSX becomes:
import { map_iterable_async as __map_iterable_async } from 'octane/tsrx-iterable';
export async function rows(items: number[]) {
return await __map_iterable_async(items, async (item) => {
return <li>{await Promise.resolve(item)}</li>;
});
}Type-checking that shape against a module that exports only map_iterable reports:
- TS2724 on the generated import:
has no exported member named 'map_iterable_async'. Did you mean 'map_iterable'? - TS7006
Parameter 'item' implicitly has an 'any' type, which maps back to the authored loop binding.itemalso loses its type on hover.
Core 0.2.x reported TS1308 ('await' expressions are only allowed within async functions) at the await instead, because the loop callback wasn't async.
Change
- Re-export
map_iterable_asyncfromsrc/tsrx-iterable.ts.@tsrx/core/runtime/iterableexports it from 0.3.0 on. - Add it to the
./tsrx-iterablerequired exports inscripts/verify-dist.mjs#L603. - Add a Volar/typecheck test: an async function with an
awaitin a@forbody produces no TS2724 or TS7006, anditemkeeps its element type.
This belongs with the upcoming upgrade to tsrx 0.3.
With the export, these functions type-check cleanly, so the editor reports nothing for them. That matches what it does today for an await in component setup code: Octane's "declared async" error appears only at build time.
Checked against Octane a95c2dc (current main) and core's createJsxTransform from tsrx main, using Octane's platform descriptor. The TS2724/TS7006 pair comes from type-checking the emitted shape against a module that exports only map_iterable. The Octane suite wasn't run.
Activity
fix: update the TSRX toolchain to @tsrx/core 0.3.2 (#1294)