Ejemplo
ts-api-utils 2.5.0: intersectionTypeParts, isAccessExpression, isConstAssertionExpression
Muestra verificada para npm ts-api-utils 2.5.0: intersectionTypeParts, isAccessExpression, isConstAssertionExpression. El contrato se ejecutó en node 22 …
sha256:8ff509d43350aaa289254b0d057ea24d7f23d4dbc85af1ab2fad42dfefade3ca
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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-28 |
Caso
HOW- Objetivo
- verify pkg:npm/ts-api-utils@2.5.0
- Paquetes
- Símbolos
-
- intersectionTypeParts
- isAccessExpression
- isConstAssertionExpression
- isFunctionScopeBoundary
- isIntersectionType
- isTypeFlagSet
- isUnionType
- unionTypeParts
- Entorno
- node 22.23.2
- Creado
- 2026-08-28T02:20:04Z
Contrato
- isUnionType and unionTypeParts decompose union types into constituent types
- isIntersectionType and intersectionTypeParts decompose intersection types
- isTypeFlagSet inspects type flags on TypeScript types
- isConstAssertionExpression identifies as const assertion expressions
- isAccessExpression identifies property and element access expressions
- isFunctionScopeBoundary identifies function declarations as scope boundaries
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código fuente
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/ts-api-utils@2.5.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ts-api-utils@2.5.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.
{"case":{"caseId":"case:sha256:b8f0805020f0eea8006488fa22f3fbece89080a5dcdc9569f9dfc2367b815562","constraints":{"executionContext":"node"},"contract":["isUnionType and unionTypeParts decompose union types into constituent types","isIntersectionType and intersectionTypeParts decompose intersection types","isTypeFlagSet inspects type flags on TypeScript types","isConstAssertionExpression identifies as const assertion expressions","isAccessExpression identifies property and element access expressions","isFunctionScopeBoundary identifies function declarations as scope boundaries"],"goal":"verify pkg:npm/ts-api-utils@2.5.0","kind":"HOW","packages":["pkg:npm/ts-api-utils@2.5.0"],"schemaVersion":1,"symbols":["intersectionTypeParts","isAccessExpression","isConstAssertionExpression","isFunctionScopeBoundary","isIntersectionType","isTypeFlagSet","isUnionType","unionTypeParts"]},"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/ts-api-utils@2.5.0"],"schemaVersion":1,"subject":"pkg:npm/ts-api-utils@2.5.0","symbols":["intersectionTypeParts","isAccessExpression","isConstAssertionExpression","isFunctionScopeBoundary","isIntersectionType","isTypeFlagSet","isUnionType","unionTypeParts"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-ts-api-utils",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-ts-api-utils",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"ts-api-utils": "2.5.0",
"typescript": "5.7.3"
}
},
"node_modules/ts-api-utils": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.5.0.tgz",
"integrity": "sha512-OJ/ibxhPlqrMM0UiNHJ/0CKQkoKF243/AEmplt3qpRgkW8VG7IfOS41h7V8TjITqdByHzrjcS/2si+y4lIh8NA==",
"license": "MIT",
"engines": {
"node": ">=18.12"
},
"peerDependencies": {
"typescript": ">=4.8.4"
}
},
"node_modules/typescript": {
"version": "5.7.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz",
"integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==",
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
}
}
}
{
"name": "sample-ts-api-utils",
"version": "1.0.0",
"type": "module",
"license": "MIT-0",
"dependencies": {
"ts-api-utils": "2.5.0",
"typescript": "5.7.3"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/ts-api-utils@2.5.0",
"kind": "HOW",
"packages": [
"pkg:npm/ts-api-utils@2.5.0"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert/strict';
import * as tsutils from 'ts-api-utils';
import ts from 'typescript';
// Setup TypeScript program and type checker for type analysis
const sourceCode = `
type StringOrNumber = string | number;
type FooAndBar = { foo: string } & { bar: number };
const constVal = [1, 2] as const;
const arrayVal = [1, 2] as number[];
const obj = { a: 1, b: 2 };
const prop = obj.a;
const elem = obj["b"];
function testFunction(x: string | number) {
if (typeof x === "string") {
return x.toUpperCase();
}
return x.toFixed(2);
}
`;
const sourceFile = ts.createSourceFile('test.ts', sourceCode, ts.ScriptTarget.Latest, true);
const defaultCompilerHost = ts.createCompilerHost({});
const customCompilerHost = {
...defaultCompilerHost,
getSourceFile: (name, languageVersion) => {
if (name === 'test.ts') return sourceFile;
return defaultCompilerHost.getSourceFile(name, languageVersion);
},
writeFile: () => {},
getDefaultLibFileName: () => defaultCompilerHost.getDefaultLibFileName({}),
useCaseSensitiveFileNames: () => true,
getCanonicalFileName: (fileName) => fileName,
getCurrentDirectory: () => '',
getNewLine: () => '\n',
fileExists: (fileName) => fileName === 'test.ts' || defaultCompilerHost.fileExists(fileName),
readFile: (fileName) => (fileName === 'test.ts' ? sourceCode : defaultCompilerHost.readFile(fileName)),
};
const program = ts.createProgram(['test.ts'], { target: ts.ScriptTarget.Latest }, customCompilerHost);
const checker = program.getTypeChecker();
// 1. isUnionType and unionTypeParts decompose union types into constituent types
const typeAliasUnion = sourceFile.statements[0];
const unionType = checker.getTypeFromTypeNode(typeAliasUnion.type);
assert.equal(tsutils.isUnionType(unionType), true, 'StringOrNumber should be identified as union type');
const unionParts = tsutils.unionTypeParts(unionType);
assert.equal(unionParts.length, 2, 'unionTypeParts should return 2 constituent types');
const unionTypeNames = unionParts.map(t => checker.typeToString(t)).sort();
assert.deepEqual(unionTypeNames, ['number', 'string'], 'union parts should be string and number');
// 2. isIntersectionType and intersectionTypeParts decompose intersection types
const typeAliasIntersection = sourceFile.statements[1];
const intersectionType = checker.getTypeFromTypeNode(typeAliasIntersection.type);
assert.equal(tsutils.isIntersectionType(intersectionType), true, 'FooAndBar should be identified as intersection type');
const intersectionParts = tsutils.intersectionTypeParts(intersectionType);
assert.equal(intersectionParts.length, 2, 'intersectionTypeParts should return 2 constituent types');
// 3. isTypeFlagSet inspects type flags on TypeScript types
assert.equal(tsutils.isTypeFlagSet(unionType, ts.TypeFlags.Union), true, 'unionType should have Union flag');
assert.equal(tsutils.isTypeFlagSet(unionParts[0], ts.TypeFlags.Union), false, 'constituent type should not have Union flag');
const stringPart = unionParts.find(t => checker.typeToString(t) === 'string');
assert.equal(tsutils.isTypeFlagSet(stringPart, ts.TypeFlags.String), true, 'string constituent should have String flag');
// 4. isConstAssertionExpression identifies as const assertion expressions
const constStmt = sourceFile.statements[2];
const constInit = constStmt.declarationList.declarations[0].initializer;
assert.equal(tsutils.isConstAssertionExpression(constInit), true, 'initializer should be identified as const assertion expression');
const arrayStmt = sourceFile.statements[3];
const arrayInit = arrayStmt.declarationList.declarations[0].initializer;
assert.equal(tsutils.isConstAssertionExpression(arrayInit), false, 'as number[] is not a const assertion expression');
// 5. isAccessExpression identifies property and element access expressions
const propStmt = sourceFile.statements[5];
const propInit = propStmt.declarationList.declarations[0].initializer;
assert.equal(tsutils.isAccessExpression(propInit), true, 'obj.a should be identified as access expression');
const elemStmt = sourceFile.statements[6];
const elemInit = elemStmt.declarationList.declarations[0].initializer;
assert.equal(tsutils.isAccessExpression(elemInit), true, 'obj["b"] should be identified as access expression');
// 6. isFunctionScopeBoundary identifies function declarations as scope boundaries
const fnStmt = sourceFile.statements[7];
assert.equal(tsutils.isFunctionScopeBoundary(fnStmt), true, 'function declaration should be a function scope boundary');
assert.equal(tsutils.isFunctionScopeBoundary(constStmt), false, 'variable statement is not a function scope boundary');
Seeder de origen
anónimo