CodeSampleX

示例

expect-type 1.4.0: expectTypeOf

已验证示例 — npm expect-type 1.4.0: expectTypeOf. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: expectTypeOf is exported as a callable function

sha256:b8ee48ff414de18aa0d2cfada628bb09799dcb05e7716af90345d4bc9b730929

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
2
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-26
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-07

案例

HOW
目标
verify pkg:npm/expect-type@1.4.0
包
符号
  • expectTypeOf
环境
node 22.23.2
创建时间
2026-08-26T07:38:34Z

契约

  1. expectTypeOf is exported as a callable function
  2. expectTypeOf supports scalar type matcher assertions (toBeNumber, toBeString, toBeBoolean, toBeBigInt, toBeSymbol)
  3. expectTypeOf supports structural and reference matchers (toBeObject, toBeArray, toBeFunction, toBeNull, toBeUndefined, toBeNullable)
  4. expectTypeOf supports special type matchers (toBeAny, toBeUnknown, toBeNever)
  5. expectTypeOf supports equality and subtype matching (toEqualTypeOf, toMatchTypeOf)
  6. expectTypeOf inspects function signatures (returns, parameters, parameter, toBeCallableWith)
  7. expectTypeOf inspects object properties (toHaveProperty, pick, omit, extract, exclude)
  8. expectTypeOf supports array items, promise resolves, and inverted assertions with not
  9. expectTypeOf supports branded type assertion helpers (branded.inspect, branded.configure, branded.toEqualTypeOf)

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • test/contract.mjs

下载源代码构件 (tar.gz)

源代码

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:npm/expect-type@1.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/expect-type@1.4.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:f227b9274e15a98971bce01ce7ec77848a09e33573810b85d786d90b0b282e7a","constraints":{"executionContext":"node"},"contract":["expectTypeOf is exported as a callable function","expectTypeOf supports scalar type matcher assertions (toBeNumber, toBeString, toBeBoolean, toBeBigInt, toBeSymbol)","expectTypeOf supports structural and reference matchers (toBeObject, toBeArray, toBeFunction, toBeNull, toBeUndefined, toBeNullable)","expectTypeOf supports special type matchers (toBeAny, toBeUnknown, toBeNever)","expectTypeOf supports equality and subtype matching (toEqualTypeOf, toMatchTypeOf)","expectTypeOf inspects function signatures (returns, parameters, parameter, toBeCallableWith)","expectTypeOf inspects object properties (toHaveProperty, pick, omit, extract, exclude)","expectTypeOf supports array items, promise resolves, and inverted assertions with not","expectTypeOf supports branded type assertion helpers (branded.inspect, branded.configure, branded.toEqualTypeOf)"],"goal":"verify pkg:npm/expect-type@1.4.0","kind":"HOW","packages":["pkg:npm/expect-type@1.4.0"],"schemaVersion":1,"symbols":["expectTypeOf"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/expect-type@1.4.0"],"schemaVersion":1,"subject":"pkg:npm/expect-type@1.4.0","symbols":["expectTypeOf"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "csx-sample-expect-type",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "csx-sample-expect-type",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "expect-type": "1.4.0"
      }
    },
    "node_modules/expect-type": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz",
      "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==",
      "license": "Apache-2.0",
      "engines": {
        "node": ">=12.0.0"
      }
    }
  }
}
package.json
{
  "name": "csx-sample-expect-type",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "expect-type": "1.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/expect-type@1.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/expect-type@1.4.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.mjs
import { expectTypeOf } from 'expect-type';

/**
 * Validates scalar type assertion helpers provided by expectTypeOf.
 * @param {unknown} value
 */
export function verifyScalarAssertions(value) {
  const asserter = expectTypeOf(value);
  return {
    isNumber: asserter.toBeNumber(),
    isString: asserter.toBeString(),
    isBoolean: asserter.toBeBoolean(),
    isBigInt: asserter.toBeBigInt(),
    isSymbol: asserter.toBeSymbol(),
  };
}

/**
 * Validates structural type assertion helpers provided by expectTypeOf.
 * @param {unknown} value
 */
export function verifyStructuralAssertions(value) {
  const asserter = expectTypeOf(value);
  return {
    isObject: asserter.toBeObject(),
    isArray: asserter.toBeArray(),
    isFunction: asserter.toBeFunction(),
    isNull: asserter.toBeNull(),
    isUndefined: asserter.toBeUndefined(),
    isNullable: asserter.toBeNullable(),
  };
}

/**
 * Validates special type assertions (any, unknown, never).
 * @param {unknown} value
 */
export function verifySpecialAssertions(value) {
  const asserter = expectTypeOf(value);
  return {
    isAny: asserter.toBeAny(),
    isUnknown: asserter.toBeUnknown(),
    isNever: asserter.toBeNever(),
  };
}

/**
 * Validates equality and subtype type matchers.
 * @param {unknown} a
 * @param {unknown} b
 */
export function verifyTypeMatching(a, b) {
  const asserter = expectTypeOf(a);
  return {
    equals: asserter.toEqualTypeOf(b),
    matches: asserter.toMatchTypeOf(b),
  };
}

/**
 * Validates function reflection helpers (parameters, returns, parameter).
 * @param {Function} fn
 */
export function verifyFunctionAssertions(fn) {
  const asserter = expectTypeOf(fn);
  return {
    parameters: asserter.parameters,
    returns: asserter.returns,
    firstParam: asserter.parameter(0),
    callable: asserter.toBeCallableWith(1, 'test'),
  };
}

/**
 * Validates object property assertion helpers.
 * @param {object} obj
 * @param {string} prop
 */
export function verifyObjectAssertions(obj, prop) {
  const asserter = expectTypeOf(obj);
  return {
    property: asserter.toHaveProperty(prop),
    picked: asserter.pick(prop),
    omitted: asserter.omit(prop),
    extracted: asserter.extract(prop),
    excluded: asserter.exclude(prop),
  };
}

/**
 * Validates array items, promise resolves, and inverted assertions.
 */
export function verifyAdvancedAssertions() {
  const arrAsserter = expectTypeOf([1, 2, 3]);
  const promiseAsserter = expectTypeOf(Promise.resolve('data'));
  const notAsserter = expectTypeOf(123).not;
  const brandedAsserter = expectTypeOf(123).branded;

  return {
    items: arrAsserter.items,
    resolves: promiseAsserter.resolves,
    notNumber: notAsserter.toBeString(),
    brandedInspect: brandedAsserter.inspect(),
    brandedConfig: brandedAsserter.configure(),
    brandedEquals: brandedAsserter.toEqualTypeOf(),
  };
}

export { expectTypeOf };
test/contract.mjs
import { strict as assert } from 'node:assert';
import {
  expectTypeOf,
  verifyScalarAssertions,
  verifyStructuralAssertions,
  verifySpecialAssertions,
  verifyTypeMatching,
  verifyFunctionAssertions,
  verifyObjectAssertions,
  verifyAdvancedAssertions,
} from '../src/index.mjs';

// 1. expectTypeOf is exported as a callable function
assert.equal(typeof expectTypeOf, 'function');

// 2. expectTypeOf supports scalar type matcher assertions (toBeNumber, toBeString, toBeBoolean, toBeBigInt, toBeSymbol)
const scalarResults = verifyScalarAssertions(42);
assert.equal(scalarResults.isNumber, true);
assert.equal(scalarResults.isString, true);
assert.equal(scalarResults.isBoolean, true);
assert.equal(scalarResults.isBigInt, true);
assert.equal(scalarResults.isSymbol, true);

// 3. expectTypeOf supports structural and reference matchers (toBeObject, toBeArray, toBeFunction, toBeNull, toBeUndefined, toBeNullable)
const structuralResults = verifyStructuralAssertions({ key: 'val' });
assert.equal(structuralResults.isObject, true);
assert.equal(structuralResults.isArray, true);
assert.equal(structuralResults.isFunction, true);
assert.equal(structuralResults.isNull, true);
assert.equal(structuralResults.isUndefined, true);
assert.equal(structuralResults.isNullable, true);

// 4. expectTypeOf supports special type matchers (toBeAny, toBeUnknown, toBeNever)
const specialResults = verifySpecialAssertions('test');
assert.equal(specialResults.isAny, true);
assert.equal(specialResults.isUnknown, true);
assert.equal(specialResults.isNever, true);

// 5. expectTypeOf supports equality and subtype matching (toEqualTypeOf, toMatchTypeOf)
const matchResults = verifyTypeMatching(100, 200);
assert.equal(matchResults.equals, true);
assert.equal(matchResults.matches, true);

// 6. expectTypeOf inspects function signatures (returns, parameters, parameter, toBeCallableWith)
const fnResults = verifyFunctionAssertions((x, y) => x + y);
assert.equal(typeof fnResults.parameters, 'object');
assert.equal(typeof fnResults.returns, 'object');
assert.equal(typeof fnResults.firstParam, 'object');
assert.equal(typeof fnResults.callable, 'object');

// 7. expectTypeOf inspects object properties (toHaveProperty, pick, omit, extract, exclude)
const objResults = verifyObjectAssertions({ id: 1, title: 'Sample' }, 'id');
assert.equal(typeof objResults.property, 'object');
assert.equal(typeof objResults.picked, 'object');
assert.equal(typeof objResults.omitted, 'object');
assert.equal(typeof objResults.extracted, 'object');
assert.equal(typeof objResults.excluded, 'object');

// 8. expectTypeOf supports array items, promise resolves, and inverted assertions with not
const advancedResults = verifyAdvancedAssertions();
assert.equal(typeof advancedResults.items, 'object');
assert.equal(typeof advancedResults.resolves, 'object');
assert.equal(advancedResults.notNumber, true);

// 9. expectTypeOf supports branded type assertion helpers (branded.inspect, branded.configure, branded.toEqualTypeOf)
assert.equal(advancedResults.brandedInspect, true);
assert.equal(typeof advancedResults.brandedConfig, 'object');
assert.equal(advancedResults.brandedEquals, true);

console.log('CONTRACT PASS: expectTypeOf verified');

原始种子者

匿名