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

fix(promise-kit): make strict typing compliant #3397

Merged
merged 2 commits into from
Jul 24, 2021

Conversation

mhofman
Copy link
Member

@mhofman mhofman commented Jun 22, 2021

Description

@agoric/promise-kit doesn't specify a types entry in its package.json causing tsc to parse its .js source to extract jsdoc typing. This parsing would also validate this internal implementation, which would raise errors when the consumer of the package is in strict mode (mostly noImplicitAny).

Security Considerations

There is a single runtime change from p.domain to 'domain' in p which is actually more correct.

Documentation Considerations

N/A

Testing Considerations

We should enable "strict": true for this package's jsconfig.json but that currently isn't possible because global.HandledPromise is only declared in @agoric/eventual-send which is not imported directly by promise-kit.

@mhofman mhofman requested review from kriskowal and michaelfig June 22, 2021 21:30
// deleting p.domain may break functionality. To retain current
// functionality at the expense of safety, set unsafe to true.
const unsafe = false;
if (unsafe) {
const originalDomain = p.domain;
const originalDomain = /** @type {*} */ (p).domain;
Copy link
Member

Choose a reason for hiding this comment

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

Is * an alias for any?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup

Copy link
Member

Choose a reason for hiding this comment

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

The convention we have in several of the packages is to use any when we really mean any, and reserve * for when we mean "I can't be bothered to type this right now, so I guess I'll punt until somebody cleans up after my mess."

Given that, I'd recommend:

Suggested change
const originalDomain = /** @type {*} */ (p).domain;
const originalDomain = /** @type {any} */ (p).domain;

Copy link
Member

Choose a reason for hiding this comment

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

The convention we have in several of the packages is to use any when we really mean any, and reserve * for when we mean "I can't be bothered to type this right now, so I guess I'll punt until somebody cleans up after my mess."

Cool. I didn't know that. Is it explained anywhere?

packages/promise-kit/src/promiseKit.js Show resolved Hide resolved
@kriskowal kriskowal requested a review from erights June 22, 2021 21:41
@erights
Copy link
Member

erights commented Jun 22, 2021

when the consumer of the package is in strict mode (mostly noImplicitAny).

This has nothing whatsoever to do with JavaScript strict-vs-sloppy mode, right?

@mhofman
Copy link
Member Author

mhofman commented Jun 22, 2021

when the consumer of the package is in strict mode (mostly noImplicitAny).

This has nothing whatsoever to do with JavaScript strict-vs-sloppy mode, right?

None whatsoever. This is purely a type checking matter (https://www.typescriptlang.org/tsconfig#strict).

Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

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

Please consider my suggested changes, but this otherwise LGTM.

// deleting p.domain may break functionality. To retain current
// functionality at the expense of safety, set unsafe to true.
const unsafe = false;
if (unsafe) {
const originalDomain = p.domain;
const originalDomain = /** @type {*} */ (p).domain;
Copy link
Member

Choose a reason for hiding this comment

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

The convention we have in several of the packages is to use any when we really mean any, and reserve * for when we mean "I can't be bothered to type this right now, so I guess I'll punt until somebody cleans up after my mess."

Given that, I'd recommend:

Suggested change
const originalDomain = /** @type {*} */ (p).domain;
const originalDomain = /** @type {any} */ (p).domain;

packages/promise-kit/src/promiseKit.js Outdated Show resolved Hide resolved
Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

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

LGTM

packages/promise-kit/src/promiseKit.js Show resolved Hide resolved
packages/promise-kit/src/promiseKit.js Show resolved Hide resolved
@mhofman mhofman force-pushed the mhofman/fix-promise-kit-internal-types branch from 87dbd90 to 3ac3679 Compare July 24, 2021 05:05
@mhofman mhofman enabled auto-merge (squash) July 24, 2021 05:10
@mhofman mhofman merged commit 69e2692 into master Jul 24, 2021
@mhofman mhofman deleted the mhofman/fix-promise-kit-internal-types branch July 24, 2021 05:37
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.

4 participants