Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up types modules #9364

Merged
merged 15 commits into from
May 16, 2024
Merged

clean up types modules #9364

merged 15 commits into from
May 16, 2024

Conversation

turadg
Copy link
Member

@turadg turadg commented May 14, 2024

no ticket

Description

Started as documentation for #9356 (comment) , then I carried out the new best practice so it would be consistent. That was a bit of a rabbit hole.

It's in a better place, though I don't see it reflected obviously in the type coverage report.

Security Considerations

n/a, types

Scaling Considerations

n/a, types

Documentation Considerations

This documents the new beset practice

Testing Considerations

CI

Upgrade Considerations

n/a, types

@turadg turadg requested review from dckc and 0xpatrickdev May 14, 2024 00:31
@turadg turadg mentioned this pull request May 14, 2024
Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

Before I approve,

  • I'd like to hear from @Chris-Hibbert about the Timestamp vs. TimestampRecord change
  • I think I should understand the use of CapData in smart-wallet better

packages/smart-wallet/src/types.ts Outdated Show resolved Hide resolved
Comment on lines -38 to 43
* @param {Timestamp} baseTime
* @param {TimestampRecord} baseTime
* @returns {import('./scheduler.js').Schedule}
*/
export const computeRoundTiming = (params, baseTime) => {
Copy link
Member

Choose a reason for hiding this comment

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

The test that's changed in eb64643 seems to show that the wider Timestamp type does work here. While narrowing the type is a longer-term goal, the fact that a test had to be changed shows that it's a breaking change.

@Chris-Hibbert what do you think about narrowing this type at this point?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is movement forward. This particular change won't have wider impacts beyond the test, so it's fine to require compliance with the target state.

Comment on lines 179 to 182
defineKind: <P, S, F>(
tag: string,
// @ts-expect-error rest parameter must be of an array type
init: (...args: P) => S,
Copy link
Member

Choose a reason for hiding this comment

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

must be array or Parameters type, right? I suppose there's no way to say "<P extends Parameters, ...>"?

I'm a little surprised that this works; i.e. that the types of the init parameters get checked. Do we happen to have a type test?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't invest in fixing these because they're all on @deprecated types

packages/zoe/src/zoeService/utils.ts Outdated Show resolved Hide resolved
@@ -290,17 +290,19 @@ export type TimeMathType = {
) => RelativeTimeRecord;
/**
* An absolute time + a relative time gives a new absolute time.
*
* @template {Timestamp} T
Copy link
Member Author

Choose a reason for hiding this comment

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

this was ignored before because it wasn't a .js file.

When I made converted the syntax, it narrowed too much all the way to the value literal. That's why made the conditional to return one of two types

@turadg
Copy link
Member Author

turadg commented May 14, 2024

gah. this will need more work.

Some packages export types at the top level like so: https://github.com/Agoric/agoric-sdk/blob/9553675cd136d389c427e024fc4da78558344779/packages/time/index.js#L3-L5

When those packages get bundled, the bundler can't find the file. This is good for safety of the bundler (it doesn't know anything about .ts) but it means we can't have .ts and export that way.

I'll see about exporting through the package.json exports patterns. But that will take a while so I'll drop this PR into draft.

@turadg turadg marked this pull request as draft May 14, 2024 19:42
Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

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

looks fine to me.

Comment on lines -38 to 43
* @param {Timestamp} baseTime
* @param {TimestampRecord} baseTime
* @returns {import('./scheduler.js').Schedule}
*/
export const computeRoundTiming = (params, baseTime) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is movement forward. This particular change won't have wider impacts beyond the test, so it's fine to require compliance with the target state.

Copy link

cloudflare-pages bot commented May 15, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: c6c0a39
Status: ✅  Deploy successful!
Preview URL: https://9b5ea2d8.agoric-sdk.pages.dev
Branch Preview URL: https://ta-use--ts.agoric-sdk.pages.dev

View logs

@turadg turadg marked this pull request as ready for review May 15, 2024 20:11
@turadg turadg requested a review from dckc May 15, 2024 20:11
@dckc
Copy link
Member

dckc commented May 15, 2024

no ticket
...

Upgrade Considerations

n/a, types

Until we release from master (#9252), even types changes can have an impact on the cost of preparing a release.

I don't think this PR makes the job much harder than it already is, but I do keep that in mind.

cc @gibson042 @mhofman

Copy link
Member

@dckc dckc 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 I'll need get more experience with this to grok fully.

but for now, it looks like a step forward

Copy link
Member

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

These look like great improvements and documentation. My main concern is how this might indeed make cherry-picking more complex for PRs stacked on top of this.


We have `"skipLibCheck": true"` in the root tsconfig.json because some libraries we depend on have their own type errors. (A massive one is the output of Telescope, used in `@agoric/cosmic-proto`.)

This means that the types you write in `.d.ts` file won't be checked by `tsc`. To gain some confidence, you can temporarily flip that setting in a package's own `tsconfig.json` and pay attention to only the relevant errors.
Copy link
Member

Choose a reason for hiding this comment

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

I didn't realize that, yikes!

- package entrypoint(s) exports explicit types
- for packages upon which other packages expect ambient types:
- `exported.js` exports the explicit types and ambient re-exports

## .d.ts modules

We cannot use `.ts` files any modules that are transitively imported into an Endo bundle. The reason is that the Endo bundler doesn't understand `.ts` syntax and we don't want it to until we have sufficient auditability of the transformation. Moreover we've tried to avoid a build step in order to import a module. (The one exception so far is `@agoric/cosmic-proto` because we codegen the types. Those modules are written in `.ts` syntax and build to `.js` by a build step that creates `dist`, which is the package export.)
Copy link
Member

Choose a reason for hiding this comment

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

Is the dist not checked in? I didn't realize we introduced a required build step. At least those files don't really change much.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct.


One option considered is having the conditional package `"exports"` include `"types"` but that has to be a .d.ts file. That could be generated from a `.ts` but it would require a build step, which we've so far avoided.

Once we have [JSDoc export type support](https://github.com/microsoft/TypeScript/issues/48104) we'll be able instead to keep the `index.js` entrypoint and have it export the types from `.ts` files without a runtime import of the module containing them.
Copy link
Member

Choose a reason for hiding this comment

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

That would be great indeed. I would likely still want the .ts file to only contain declare statements.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed!

@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label May 16, 2024
@turadg turadg changed the title use .ts for types modules clean up types modules May 16, 2024
@turadg turadg removed the automerge:rebase Automatically rebase updates, then merge label May 16, 2024
@turadg
Copy link
Member Author

turadg commented May 16, 2024

These look like great improvements and documentation.
Thanks.

My main concern is how this might indeed make cherry-picking more complex for PRs stacked on top of this.

To help I've reduced the number of changes. I hope they'll be obvious to resolve in a merge.

Another reason I reduced them is I realized the pack check should really be a prepack check (documented in the CI script) and some of the cleanup wasn't compatible with that.

@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label May 16, 2024
@mergify mergify bot merged commit 0f94e34 into master May 16, 2024
71 checks passed
@mergify mergify bot deleted the ta/use-.ts branch May 16, 2024 18:18
@turadg turadg mentioned this pull request May 16, 2024
mergify bot added a commit that referenced this pull request May 16, 2024
refs: #9364

## Description

Follow-up to #9364, also doing the `skipLibCheck: false` for Zoe package
and fixing up most of the issues. (Documenting the deferred).


### Security Considerations

<!-- Does this change introduce new assumptions or dependencies that, if
violated, could introduce security vulnerabilities? How does this PR
change the boundaries between mutually-suspicious components? What new
authorities are introduced by this change, perhaps by new API calls?
-->

### Scaling Considerations

<!-- Does this change require or encourage significant increase in
consumption of CPU cycles, RAM, on-chain storage, message exchanges, or
other scarce resources? If so, can that be prevented or mitigated? -->

### Documentation Considerations

<!-- Give our docs folks some hints about what needs to be described to
downstream users.

Backwards compatibility: what happens to existing data or deployments
when this code is shipped? Do we need to instruct users to do something
to upgrade their saved data? If there is no upgrade path possible, how
bad will that be for users?

-->

### Testing Considerations

<!-- Every PR should of course come with tests of its own functionality.
What additional tests are still needed beyond those unit tests? How does
this affect CI, other test automation, or the testnet?
-->

### Upgrade Considerations

just types and tests. will not affect production but small impact on
release process (cherry picking)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants