Exemple
ts-api-utils 2.5.0: intersectionTypeParts, isAccessExpression, isConstAssertionExpression
Échantillon vérifié pour npm ts-api-utils 2.5.0: intersectionTypeParts, isAccessExpression, isConstAssertionExpression. Le contrat s'est exécuté sur node 22…
sha256:8ff509d43350aaa289254b0d057ea24d7f23d4dbc85af1ab2fad42dfefade3ca
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify pkg:npm/ts-api-utils@2.5.0
- Paquets
- Symboles
-
- intersectionTypeParts
- isAccessExpression
- isConstAssertionExpression
- isFunctionScopeBoundary
- isIntersectionType
- isTypeFlagSet
- isUnionType
- unionTypeParts
- Environnement
- node 22.23.2
- Créé
- 2026-08-28T02:20:04Z
Contrat
- 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
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Code source
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 d'origine
anonyme