ReqResult's data and error are typed as always present but are undefined in practice
- Ngôn ngữ chính
- TypeScript
- Star
- 29
- Fork
- 3
- Merge trung bình
- 3 giờ 5 phút
- Pull request đã merge (30 ngày)
- 11
Mô tả
```ts
export interface ReqResult {
data: Readable;
status: Readable;
error: Readable;
}
```
Neither `data` nor `error` is actually always present:
- `error` is `undefined` until something fails, which is the normal case for a
whole request. `useReq.test.ts` asserts exactly that ("emits undefined as
.error"), and `useReq()` builds it from `writable()` with a
cast at the boundary.
- `data` is `undefined` for every single-event hook — `useEvent`, `useMetadata`,
`useArticle`, `useLatestEvent`, `useReplaceableEvent` and the wrappers around
them — while the request is in flight, and permanently when the event does not
exist. Those hooks pass no `initData`, and there is no sensible `EventPacket`
to stand in for "not found".
The components already work around it: every one of them writes `$data?.…`
rather than `$data.…`. Consumers using the hooks directly get no such warning
from the compiler — the type says the value is there.
This is what #59 fixed one instance of, by giving `useUniqueEventList()` the
`initData: []` its siblings already had. That closed the gap for the list hooks,
whose `[]` is a real value. It cannot be closed the same way for the
single-event ones.
## Why it isn't just a one-line change
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.