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

mustMatch support for TypedPattern #2611

Open
dckc opened this issue Oct 24, 2024 · 1 comment
Open

mustMatch support for TypedPattern #2611

dckc opened this issue Oct 24, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@dckc
Copy link
Contributor

dckc commented Oct 24, 2024

What is the Problem Being Solved?

after a typeof x === 'string' test, the type of x is refined to string.
But we don't get the same benefit from mustMatch(x, M.string()).

Description of the Design

migrate from @agoric/internal. In particular, in @agoric/internal's typeCheck.test.js:

const Mstring = /** @type {TypedPattern<string>} */ (M.string());
const unknownString = /** @type {unknown} */ ('');

test('mustMatch', t => {
  // @ts-expect-error unknown type
  unknownString.length;
  mustMatch(unknownString, Mstring);
  unknownString.length;
  t.pass();
});

Security Considerations

TypedPattern<T> can make claims that are stronger than the pattern actually enforces.

Scaling Considerations

none

Test Plan

port tests from agoric-sdk

Compatibility / Upgrade Considerations

none that I can think of

cc @turadg @erights

@dckc dckc added the enhancement New feature or request label Oct 24, 2024
@turadg
Copy link
Member

turadg commented Oct 24, 2024

Thanks for filing. Here's the TODO line in agoric-sdk: https://github.com/Agoric/agoric-sdk/blob/1cb791553d0d27df9953304e556652c216988909/packages/store/src/index.js#L63-L67

Of course meanwhile it's fine to import mustMatch from @agoric/internal or @agoric/store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants