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

more ts syntax #8335

Merged
merged 10 commits into from
Sep 16, 2023
Merged

more ts syntax #8335

merged 10 commits into from
Sep 16, 2023

Conversation

turadg
Copy link
Member

@turadg turadg commented Sep 14, 2023

Description

Motivation was to be able to document the promises in BootstrapSpace. That required adopting .ts syntax. I experimented with some more conversions.

Security Considerations

none

Scaling Considerations

n/a

Documentation Considerations

We should convert the whole codebase to this style for consistency,
-#8342

Testing Considerations

CI suffices

Upgrade Considerations

n/a

@turadg turadg requested review from mhofman and dckc September 14, 2023 23:06
Copy link
Member

Choose a reason for hiding this comment

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

This should be types.d.ts no?

Copy link
Member

Choose a reason for hiding this comment

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

A '*.ts' file does seem to be unprecedented.

We have some *.d.ts and some *.test-d.ts (including one in vat-data/src) but no *.ts:

$ find . -name node_modules -prune -o -name moddable -prune -o \
  -name '*.d.ts' -name '*.test-d.ts' -prune -o -prune -o \
  -name '*.ts' -print
$

Copy link
Member

Choose a reason for hiding this comment

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

To be clear, I have no problem with .ts files for tests, and those do exist in the endo repo, I guess not (yet) in agoric-sdk.

And it's very much possible that a bare .ts works in this case too, but I would find it too confusing and error prone as it's semantically different than types declarations only, which we want.

@mhofman
Copy link
Member

mhofman commented Sep 14, 2023

Small reviewing nit: it would have been nice to have a commit renaming / converting type.js -> types.d.ts, then a second commit adding back the "empty" types.js for diffing purposes and possibly for conflict resolutions in the future.

@mhofman mhofman self-requested a review September 14, 2023 23:12
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'm hesitant to make a runtime change (however small) to the bootstrap vat in a PR about changing how types are written.

* Informs Zoe about an issuer and returns a promise for acknowledging
* when the issuer is added and ready.
*/
type SaveIssuer = (
Copy link
Member

Choose a reason for hiding this comment

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

I suppose it pre-dates this PR, but...

This type suggests there might be other implementations of SaveIssuer. Seems like it should be inlined.

packages/vats/src/core/chain-behaviors.js Outdated Show resolved Hide resolved
@@ -2,7 +2,9 @@
const start = zcf => {
/** @type {OfferHandler} */
const handler = (_seat, offerArgs) => {
// @ts-expect-error xxx HandleOffer
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit reluctant to speak for @Chris-Hibbert and @erights re maintaining zoe package types in typescript rather than JSDoc, but I suppose this sort of thing shows that maintenance was suffering anyway.

Copy link
Member

Choose a reason for hiding this comment

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

This approach seems to get us closer to single-source for API docs (#4291). @erights said that made would make this well worth it.

*/

/** @template T @typedef {{vatPowers: { D: DProxy }, devices: T}} BootDevices<T> */
// Dummy file for .ts twin to declare ambients
Copy link
Member

Choose a reason for hiding this comment

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

Ambient ts is an interesting approach...

packages/vats/src/core/chain-behaviors.js Outdated Show resolved Hide resolved
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.

just questions. I'm no authority.

>
>;
walletFactory: Promise<
Installation<import('@agoric/smart-wallet/src/walletFactory.js').start>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a typo, or is typeof required here? The cases above needed it.

Suggested change
Installation<import('@agoric/smart-wallet/src/walletFactory.js').start>
Installation<typeof import('@agoric/smart-wallet/src/walletFactory.js').start>

Copy link
Member Author

Choose a reason for hiding this comment

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

yes. .ts syntax is less forgiving that .js/JSDoc syntax in this regard

Comment on lines 475 to 477
type AgoricNamesVat = ERef<
ReturnType<typeof import('../vat-agoricNames').buildRootObject>
>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does typescript allow one to make shorthand for the oft-repeated ERef<ReturnType<typeof importedThing.buildRootObject>>?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good idea! We can have a utility type for the root object of a vat.

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 tried DRYing out the buildRootObject reference but I haven't found a way to get the module import to be a generic type for s helper. It might require a module import, which would break this being an ambient.

We could DRY the ERef<ReturnType< but it wouldn't save a lot of characters unless we also do a helper like ContractInstallationPromises (which I just added). I expect eventually we'll want one for devices to be keys in a namespace instead of named by concatenation

@@ -9,6 +9,7 @@
"*.js",
"scripts/**/*.js",
"src/**/*.js",
"src/**/*.ts",
Copy link
Member

Choose a reason for hiding this comment

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

Should this be

Suggested change
"src/**/*.ts",
"src/**/*.d.ts",

Copy link
Member Author

Choose a reason for hiding this comment

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

What's here works, but would allow src to have runtime .ts files so I think your suggestion is worth including. I'll do it in a cleanup push

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 trust you'll also reach consensus with @mhofman and co.

@turadg turadg requested a review from mhofman September 16, 2023 03:51
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.

Ok I think my confusion came from the fact that some bundlers or other pieces of tooling would fail if importing a js file that isn't a module by heuristics (aka doesn't have any import or export statement), but apparently that's not a problem since both before and after the type.js file doesn't have those statements, and it is runtime imported. So all clear on my end, sorry for the confusion.

@turadg turadg force-pushed the ta/doc-bootspace-powers branch from cd7c7ee to 365be75 Compare September 16, 2023 05:09
@turadg
Copy link
Member Author

turadg commented Sep 16, 2023

came from the fact that some bundlers or other pieces of tooling would fail if importing a js file that isn't a module by heuristics (aka doesn't have any import or export statement)

Your concern was well-placed! The typescript-eslint plugin was failing to load the empty .js files. I have included this work-around: 365be75

@turadg turadg force-pushed the ta/doc-bootspace-powers branch 2 times, most recently from 6aea57b to c6c5acb Compare September 16, 2023 14:58
@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label Sep 16, 2023
@turadg turadg force-pushed the ta/doc-bootspace-powers branch from c6c5acb to 7edc3e9 Compare September 16, 2023 20:49
@mergify mergify bot merged commit 3da32ff into master Sep 16, 2023
71 checks passed
@mergify mergify bot deleted the ta/doc-bootspace-powers branch September 16, 2023 21:29
@turadg
Copy link
Member Author

turadg commented Sep 17, 2023

The eslintconfig change wasn't reviewed. I merged to reduce the risk of merge conflicts and ease building atop it. But if anyone has a better solution or request I'm happy to hear them and will follow up.

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.

5 participants