Skip to content

Conversation

rekmarks
Copy link
Contributor

Refs: #1831, Agoric/agoric-sdk#11931

Description

We wish to visibly deprecate the sloppy option of @endo/patterns interface guards. To avoid an explosion of @typedef blocks, we migrate the @endo/patterns types to TypeScript and then add the minimally required @deprecated tags.

Security Considerations

N/A

Scaling Considerations

N/A

Documentation Considerations

N/A

Testing Considerations

This modifies the implementation of the @endo/patterns types, but should not modify them. Since the number of lines changed is larged, we should attempt to convince ourselves that the types are in fact the same.

Compatibility Considerations

N/A

Upgrade Considerations

Deprecates but does not remove the sloppy option. NEWS.md is updated.

@rekmarks rekmarks force-pushed the rekm/patterns-typescript branch from 6928018 to ebbe21d Compare September 16, 2025 19:32
Comment on lines 21 to 24
".": {
"types": "./types.d.ts",
"default": "./index.js"
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still prefer to have an export * from './types.js' in index.js (with types.js being a stub export {})

@@ -0,0 +1,2 @@
export * from './src/types.js';
export * from './index.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed if switching to index.js re-exporting types.js

Comment on lines 3 to 5
import { isKey, isScalarKey } from '../src/keys/checkKey.js';
import { M } from '../src/patterns/patternMatchers.js';
import type { Key, ScalarKey } from '../src/types.js';
import type { Key, ScalarKey } from '../src/types.ts';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I prefer types tests to import from the entrypoint like a dependency would.

@rekmarks rekmarks marked this pull request as ready for review September 16, 2025 19:52
@rekmarks
Copy link
Contributor Author

@mhofman I made your requested changes in 598ce27 but am now getting CI failures during prepack:

➤ YN0000: @endo/patterns@workspace:packages/patterns STDOUT error TS5055: Cannot write file '/home/runner/work/endo/endo/packages/patterns/src/patterns/types.d.ts' because it would overwrite input file.
➤ YN0000: @endo/patterns@workspace:packages/patterns STDOUT error TS5055: Cannot write file '/home/runner/work/endo/endo/packages/patterns/src/types.d.ts' because it would overwrite input file.

I can't seem to find any differences in the tsconfig files of other packages that use your preferred pattern, such as compartment-mapper. Is it the file names that are the problem?

Also, other packages, e.g. daemon appear to use the pattern I first resorted to. Are we trying to move to one vs. the other?

Copy link
Contributor

@mhofman mhofman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the confusion is where a manual .d.ts / .js pair is needed, and where .ts is sufficicient.

  • .d.ts / stub .js only for the entrypoint. No meaningful content, just .d.ts re-exporting .js files, which are actually authored as .ts. There cannot be a .ts of the same name. We usually name this one types-index.{d.ts,js}
  • .ts (without any .js sibling) for type definitions. It cannot contain any runtime code. The prepack step will generate a .d.ts file (which should be equivalent to the .ts file), and a .js files (which should be empty).

Does that make sense?

@rekmarks
Copy link
Contributor Author

rekmarks commented Sep 16, 2025

@mhofman I see. There were no existing examples of the index-types.* pattern in endo, but I applied it in a2ea252.

Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

Copy link
Contributor

@mhofman mhofman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not reviewed the actual change of the types.js -> types.ts.

@rekmarks rekmarks force-pushed the rekm/patterns-typescript branch from e8a852b to 3f20f4f Compare September 17, 2025 22:26
@rekmarks rekmarks enabled auto-merge September 17, 2025 22:26
@rekmarks rekmarks merged commit 52104f6 into master Sep 17, 2025
19 checks passed
@rekmarks rekmarks deleted the rekm/patterns-typescript branch September 17, 2025 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants