Compare commits
2
Commits
5118c5c9b0
...
9c75e44fef
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c75e44fef | ||
|
|
8eaff2bf7a |
No files matched your search
@@ -26,6 +26,8 @@ Code](https://code.claude.com/docs/en/skills) and
|
||||
instrument.
|
||||
- [silent-failures-are-evil](silent-failures-are-evil/SKILL.md) — every
|
||||
failure path leaves a trace in the logs.
|
||||
- [typed-remotes](typed-remotes/SKILL.md) — `Remote<X>`, never a bare
|
||||
`Remote`; `@satisfies`, not `@type`; and a lint rule so it stays fixed.
|
||||
- [lazy-tdd](lazy-tdd/SKILL.md) — works the first time? fine. Goofed?
|
||||
You owe a test.
|
||||
- [py-doctest](py-doctest/SKILL.md) — Python tests are doctests on the
|
||||
|
||||
@@ -25,6 +25,8 @@ When you rewrite a wrapped paragraph, unwrap it. Don't unwrap a whole file you a
|
||||
|
||||
Obsidian shows file names in tabs, the file explorer, and search, so name files for what's in them.
|
||||
|
||||
Avoid `README.md` for notes in a vault: a folder of them shows as a row of tabs all named "README". Name the file for its folder's subject (`gadget-tub/gadget-tub.md`). A repo's top-level README is the exception; GitHub needs it.
|
||||
|
||||
Headings show in Obsidian's outline pane: make them say something.
|
||||
|
||||
## Frontmatter
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
---
|
||||
name: typed-remotes
|
||||
description: >-
|
||||
Typed references in Endo / toybox / Agoric JSDoc — use when writing or reviewing a vat's `Params` typedef, a `buildRootObject`, a store that holds references, or any `@param`/`@property`/`@type` that names another vat's object or a device; when about to write a bare `Remote`, `Remote[]`, `{any}`, or `@type {BuildRootObject<...>}`; when someone says "Params has a bunch of any", "it won't stay fixed", or "type the remotes". Not for whether a reference should be handed over at all (that's pola).
|
||||
---
|
||||
|
||||
# Typed remotes
|
||||
|
||||
A bare `Remote` is `Remote<any>`. Every call through it, and everything
|
||||
it answers, goes unchecked, so a wrong method name or a misread answer
|
||||
gets through `tsc --checkJs` and fails at runtime, in another vat.
|
||||
|
||||
## The rule
|
||||
|
||||
- **Name what the reference is:** `Remote<X>`, never `Remote` or
|
||||
`Remote[]`. `X` is:
|
||||
- for another vat's root, that vat's own type, exported beside its
|
||||
code: `/** @typedef {ReturnType<typeof buildRootObject>} Cache */`
|
||||
- for a facet it hands out, the method's answer:
|
||||
`ReturnType<Cache['viewer']>`
|
||||
- for a device or a platform vat with no exported type, a small
|
||||
interface naming the calls this code makes, in one `types.ts`
|
||||
- **Declare `buildRootObject` with `@satisfies`, not `@type`:**
|
||||
`/** @satisfies {BuildRootObject<Params>} */`. `@type` checks the
|
||||
params but answers only `object`, so `ReturnType<typeof
|
||||
buildRootObject>` is useless; `@satisfies` checks the same and keeps
|
||||
what it infers.
|
||||
- **One cast, where the type is truly lost, and it says why.** The
|
||||
kernel answers only "some vat's root" for `createVat`. Look roots up
|
||||
through one accessor typed by a role table:
|
||||
|
||||
```js
|
||||
/** @typedef {{ cache: Cache, gateway: Gateway }} Roles */
|
||||
/**
|
||||
* it's the vat Roles names because ensure made it from that role's code
|
||||
* @template {keyof Roles} R @param {R} role @returns {Remote<Roles[R]>}
|
||||
*/
|
||||
const rootOf = role => /** @type {Remote<Roles[R]>} */ (vats.get(role).root);
|
||||
```
|
||||
|
||||
- **`unknown`, not `any`,** for what isn't checked yet, such as parsed
|
||||
JSON: `{{ key?: unknown, at?: unknown }}`. Then narrow with a check.
|
||||
- **Type the store's values too:** `MapStore<keyof State, State[keyof
|
||||
State]>` with `put`/`got` generic over the key, not
|
||||
`MapStore<string, any>`.
|
||||
|
||||
## Make it stay fixed
|
||||
|
||||
A fix to the code alone drifts back: the next agent copies the nearest
|
||||
example, or a doc that blesses `Remote` as the place `any` is fine.
|
||||
|
||||
- Fix the **guidance** that licensed it (CONTRIBUTING, AGENTS.md), not
|
||||
just the instances.
|
||||
- Add a **lint rule** that rejects a bare `Remote` or `any` in JSDoc
|
||||
types, on the files that are clean now, and widen its `files` as more
|
||||
get typed. vattr97's `eslint-typed-refs.mjs` is one, with no
|
||||
dependencies: it finds each type tag's balanced `{...}` in JSDoc
|
||||
comments and flags `\bany\b` and `\bRemote\b(?!\s*<)`.
|
||||
- After typing, **remove the test's `any`s**: they hid the same gaps
|
||||
in the code under test (one, here, hid a store typed so that
|
||||
`got('user')` was always `undefined`).
|
||||
|
||||
## Sources
|
||||
|
||||
- [@agoric/internal types.ts](https://github.com/Agoric/agoric-sdk/blob/master/packages/internal/src/types.ts) — the `Remote` that toybox's follows, `any` by default.
|
||||
- [TypeScript 4.9: the satisfies operator](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html#the-satisfies-operator) — checks a type without widening what's inferred; JSDoc `@satisfies` since 5.0.
|
||||
Reference in new issue
Block a user