Repository navigation
Commit 7be5ba0
committed
🔧 Prevent contracts from exposing concrete generator types
Generator and AsyncGenerator are the types of the object a function*
produces. Naming one is right when a declaration really is handing a
consumer a sequence, so local/prefer-effection-operation reports the
narrower thing: the concrete type standing in for Effection work.
The yield type settles which is which. A generator that serves a consumer
names what it yields; one that yields unknown — or nothing, or any —
offers a consumer nothing it can use, which is work waiting for a runner.
Effection work yields effects. Everything else is iteration and passes,
Generator<number, void, unknown> included.
A name is not evidence that a type is an effect: SoundEffect is a sound.
An effect is Effect imported from effection, however it is spelled at the
import; a type this module declares out of one; or a type this module
declares with the effect contract itself — description annotated string,
and enter a two-parameter signature returning a function type. Both
shapes are checked, because names are cheap: { description: number;
enter: boolean } is a doorway. That branch is how DurableEffect is
recognized: it restates the contract rather than extending it, to keep
enter's variance under its own control, so nothing in its declaration
names Effection at all.
Shadowing is lexical. A module-level import or declaration covers the
module; a nested declaration or a type parameter covers only its own
scope, so a contract declared after one still names the built-in.
globalThis.Generator reaches past every shadow.
Choosing between Operation<T> and naming what a generator yields is a
decision about what the declaration means, so there is no fix.
Workflow<T> keeps its concrete yield type — that is what stops a workflow
yielding a non-durable effect — behind a suppression at that one line.
Closes #1851 parent aa47442 commit 7be5ba0
14 files changed
Lines changed: 828 additions & 0 deletions
File tree
- packages/durable-streams
- scripts
- oxlint-rules
- tests
- fixtures
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
141 | 142 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
0 commit comments