-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types): fromCapData is Passable, but unknown is more practical
- Loading branch information
Showing
7 changed files
with
38 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
import { expectType, expectNotType } from 'tsd'; | ||
|
||
import type { PrimitiveStyle } from '@endo/pass-style'; | ||
import { | ||
Far, | ||
type PrimitiveStyle, | ||
type RemotableObject, | ||
} from '@endo/pass-style'; | ||
import { makeMarshal } from './marshal.js'; | ||
|
||
expectType<PrimitiveStyle>('string'); | ||
expectType<PrimitiveStyle>('number'); | ||
// @ts-expect-error | ||
expectType<PrimitiveStyle>(1); | ||
// @ts-expect-error | ||
expectType<PrimitiveStyle>('str'); | ||
|
||
type KCap = RemotableObject & { getKref: () => string; iface: () => string }; | ||
const valToSlot = (s: KCap) => s.getKref(); | ||
const slotToVal = (s: string) => null as unknown as KCap; | ||
const marshal = makeMarshal(valToSlot, slotToVal); | ||
const cycled = marshal.fromCapData(marshal.toCapData(null as unknown as KCap)); | ||
expectType<unknown>(cycled); | ||
|
||
const m = makeMarshal(); | ||
type SlottedRemotable = { getBoardId: () => string }; | ||
const foo = Far('foo'); | ||
const foo1 = Far('foo', { getBoardId: () => 'board1' }); | ||
const foo2 = Far('foo', { getBoardId: () => 'board2' }); | ||
const bar = Far('bar'); | ||
const bar1 = Far('bar', { getBoardId: () => 'board1' }); | ||
m.toCapData(harden({ o: foo1 })); | ||
m.toCapData(harden({ o: foo2 })); | ||
m.toCapData(harden({ o: bar1 })); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters