akiomik / akiomik/nosvelte

ReqResult's data and error are typed as always present but are undefined in practice

Đang mở
#69 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
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

`data: Readable` and `error: Readable` are the
honest types, but they break every TypeScript consumer that currently writes
`$data.event` or `$error.message` — the compiler starts rejecting code that
works today. That makes it a minor release, and worth deciding alongside
whether the list and single-event hooks should keep sharing one result type at
all.

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á.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.