Skip to content

Commit

Permalink
chore(types): consolidate PassStyled type
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jan 11, 2024
1 parent 418b2da commit ddcdad1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/pass-style/src/passStyle-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ harden(checkNormalProperty);

/**
* @template {import('./types.js').InterfaceSpec} T
* @param {import('./types.js').TaggedRecord<any, T>} tagRecord
* @param {import('./types.js').PassStyled<any, T>} tagRecord
* @returns {T}
*/
export const getTag = tagRecord => tagRecord[Symbol.toStringTag];
Expand All @@ -144,7 +144,7 @@ harden(checkPassStyle);

const makeCheckTagRecord = checkProto => {
/**
* @param {import('./types.js').TaggedRecord<any, any>} tagRecord
* @param {import('./types.js').PassStyled<any, any>} tagRecord
* @param {PassStyle} passStyle
* @param {Checker} [check]
* @returns {boolean}
Expand Down
2 changes: 1 addition & 1 deletion packages/pass-style/src/remotable.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const checkRemotable = (val, check) => {
/**
* Simple semantics, just tell what interface (or undefined) a remotable has.
* @type {{
* <T extends string>(val: import('./types.js').TaggedRecord<any, T>): T;
* <T extends string>(val: import('./types.js').PassStyled<any, T>): T;
* (val: any): string | undefined;
* }}
* @returns the interface specification, or undefined

Check warning on line 175 in packages/pass-style/src/remotable.js

View workflow job for this annotation

GitHub Actions / lint (16.x, ubuntu-latest)

Missing JSDoc @returns type
Expand Down
22 changes: 11 additions & 11 deletions packages/pass-style/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ export type PassStyle =

export type TaggedOrRemotable = 'tagged' | 'remotable';

export type PassStyled<S extends TaggedOrRemotable> = {
/**
* Tagged has own [PASS_STYLE]: "tagged", [Symbol.toStringTag]: $tag.
*
* Remotable has a prototype chain in which the penultimate object has own [PASS_STYLE]: "remotable", [Symbol.toStringTag]: $iface (where both $tag and $iface must be strings, and the latter must either be "Remotable" or start with "Alleged: " or "DebugName: ").
*/
export type PassStyled<S extends TaggedOrRemotable, I extends InterfaceSpec> = {
[PASS_STYLE]: S;
[Symbol.toStringTag]: I;
};

export type ExtractStyle<P extends PassStyled<any>> = P[typeof PASS_STYLE];
export type ExtractStyle<P extends PassStyled<any, any>> = P[typeof PASS_STYLE];

export type PassByCopy =
| Primitive
Expand Down Expand Up @@ -103,7 +109,7 @@ export type PassStyleOf = {
(p: any[]): 'copyArray';
(p: Iterable<any>): 'remotable';
(p: Iterator<any, any, undefined>): 'remotable';
<T extends PassStyled<TaggedOrRemotable>>(p: T): ExtractStyle<T>;
<T extends PassStyled<TaggedOrRemotable, any>>(p: T): ExtractStyle<T>;
(p: { [key: string]: any }): 'copyRecord';
(p: any): PassStyle;
};
Expand All @@ -130,20 +136,14 @@ export type PassStyleOf = {
* any potential proxies.
*/
export type PureData = Passable<never, never>;
export type TaggedRecord<
S extends TaggedOrRemotable,
I extends InterfaceSpec,
> = PassStyled<S> & {
[Symbol.toStringTag]: I;
};
/**
* An object marked as remotely accessible using the `Far` or `Remotable`
* functions, or a local presence representing such a remote object.
*
* A more natural name would be Remotable, but that could be confused with the
* value of the `Remotable` export of this module (a function).
*/
export type RemotableObject<I extends InterfaceSpec = string> = TaggedRecord<
export type RemotableObject<I extends InterfaceSpec = string> = PassStyled<
'remotable',
I
>;
Expand Down Expand Up @@ -171,7 +171,7 @@ export type CopyRecord<T extends Passable = any> = Record<string, T>;
export type CopyTagged<
Tag extends string = string,
Payload extends Passable = any,
> = TaggedRecord<'tagged', Tag> & {
> = PassStyled<'tagged', Tag> & {
payload: Payload;
};
/**
Expand Down

0 comments on commit ddcdad1

Please sign in to comment.