Skip to content

mustMatch support for TypedPattern #2611

@dckc

Description

@dckc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions