CodeSampleX

Ejemplo

@typescript-eslint/scope-manager 8.65.0: TypeScope

Muestra verificada para npm @typescript-eslint/scope-manager 8.65.0: TypeScope. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:ae7923526da91fd17c29ece70a4175a85ee55387065a1c6152d830364b57103d

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 linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-05

Caso

HOW
Objetivo
verify @typescript-eslint/scope-manager.TypeScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0
Paquetes
Símbolos
  • @typescript-eslint/scope-manager.TypeScope
Creado
2026-09-05T18:26:13Z

Contrato

  1. TypeScope is exported by @typescript-eslint/scope-manager and instantiates with type ScopeType, upper scope, and block AST node
  2. ScopeManager.nestTypeScope creates and registers a TypeScope within the active scope hierarchy
  3. analyze produces a TypeScope for generic TSTypeAliasDeclaration with its type parameters recorded in variables and set
  4. analyze produces a TypeScope for generic TSInterfaceDeclaration with its type parameters recorded in variables and resolved in interface body
  5. TypeScope confines type parameters so they cannot be resolved outside their declaration scope

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 @typescript-eslint/scope-manager.TypeScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40typescript-eslint/scope-manager@8.65.0
Demonstrate these symbols/APIs:
  - @typescript-eslint/scope-manager.TypeScope

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:ae7dab85fd8995bd71015bc8a4642877b87e6a75d5d0b90eeb5706f9cde9df1c","contract":["TypeScope is exported by @typescript-eslint/scope-manager and instantiates with type ScopeType, upper scope, and block AST node","ScopeManager.nestTypeScope creates and registers a TypeScope within the active scope hierarchy","analyze produces a TypeScope for generic TSTypeAliasDeclaration with its type parameters recorded in variables and set","analyze produces a TypeScope for generic TSInterfaceDeclaration with its type parameters recorded in variables and resolved in interface body","TypeScope confines type parameters so they cannot be resolved outside their declaration scope"],"goal":"verify @typescript-eslint/scope-manager.TypeScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0","kind":"HOW","packages":["pkg:npm/%40typescript-eslint/scope-manager@8.65.0"],"schemaVersion":1,"symbols":["@typescript-eslint/scope-manager.TypeScope"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40typescript-eslint/scope-manager@8.65.0"],"schemaVersion":1,"subject":"pkg:npm/%40typescript-eslint/scope-manager@8.65.0","symbols":["@typescript-eslint/scope-manager.TypeScope"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-scope-manager-type-scope",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-scope-manager-type-scope",
      "version": "1.0.0",
      "dependencies": {
        "@typescript-eslint/scope-manager": "8.65.0"
      }
    },
    "node_modules/@typescript-eslint/scope-manager": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.65.0.tgz",
      "integrity": "sha512-Esbl8OSYiVxBokYgWPf7VVWg/BE798wXhimnn9ML9Pt5qoDf8bfQlgjlKXR/k98+AcNzlLKYrpCcrcuZ9DZLgg==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/types": "8.65.0",
        "@typescript-eslint/visitor-keys": "8.65.0"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      }
    },
    "node_modules/@typescript-eslint/types": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.65.0.tgz",
      "integrity": "sha512-JSSwWNy+H0E/01jJEM+hrX6N0OFDzFzeIhHFSAS01tlVaevpG8cFyYRPhS5yjGOvBUx3sqQHVMjCL1CAZZMxBg==",
      "license": "MIT",
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      }
    },
    "node_modules/@typescript-eslint/visitor-keys": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.65.0.tgz",
      "integrity": "sha512-8C71BQkGjiMmXtop7pHVJu1l2NNShFdkCyD6a2ezzs5vU/L3LRtb69EtcteFwz0mYMPzIgOw0n6OV4VBUWZd7A==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/types": "8.65.0",
        "eslint-visitor-keys": "^5.0.0"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      }
    },
    "node_modules/eslint-visitor-keys": {
      "version": "5.0.1",
      "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz",
      "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==",
      "license": "Apache-2.0",
      "engines": {
        "node": "^20.19.0 || ^22.13.0 || >=24"
      },
      "funding": {
        "url": "https://opencollective.com/eslint"
      }
    }
  }
}
package.json
{
  "name": "verify-scope-manager-type-scope",
  "version": "1.0.0",
  "private": true,
  "description": "verify @typescript-eslint/scope-manager.TypeScope in pkg:npm/@typescript-eslint/scope-manager@8.65.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@typescript-eslint/scope-manager": "8.65.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @typescript-eslint/scope-manager.TypeScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40typescript-eslint/scope-manager@8.65.0"
  ],
  "symbols": [
    "@typescript-eslint/scope-manager.TypeScope"
  ]
}
src/index.js
const { ScopeManager, TypeScope, analyze } = require('@typescript-eslint/scope-manager');

/**
 * Creates an instance of TypeScope directly given a ScopeManager, upper scope, and AST block node.
 *
 * @param {ScopeManager} scopeManager - The managing ScopeManager instance
 * @param {import('@typescript-eslint/scope-manager').Scope} upperScope - The parent scope
 * @param {object} blockNode - The AST node defining the type scope (e.g. TSInterfaceDeclaration, TSTypeAliasDeclaration)
 * @returns {TypeScope} The newly instantiated TypeScope
 */
function createTypeScope(scopeManager, upperScope, blockNode) {
  return new TypeScope(scopeManager, upperScope, blockNode);
}

/**
 * Nests a TypeScope within an existing ScopeManager hierarchy for an AST node.
 *
 * @param {ScopeManager} scopeManager - The ScopeManager instance
 * @param {object} blockNode - The AST node defining the type scope
 * @returns {TypeScope} The nested TypeScope
 */
function nestTypeScopeInManager(scopeManager, blockNode) {
  return scopeManager.nestTypeScope(blockNode);
}

/**
 * Analyzes an ESTree/TSESTree Program AST and returns all TypeScope instances.
 *
 * @param {object} ast - The ESTree Program AST node
 * @param {object} [options={}] - Optional analyzer options
 * @returns {TypeScope[]} Array of TypeScope instances found in the analyzed AST
 */
function findTypeScopes(ast, options = {}) {
  const scopeManager = analyze(ast, options);
  return scopeManager.scopes.filter((scope) => scope instanceof TypeScope);
}

/**
 * Extracts variable names defined within a TypeScope (e.g., type parameter identifiers).
 *
 * @param {TypeScope} typeScope - The TypeScope instance
 * @returns {string[]} Array of declared type variable names
 */
function getTypeVariableNames(typeScope) {
  return typeScope.variables.map((variable) => variable.name);
}

module.exports = {
  TypeScope,
  ScopeManager,
  analyze,
  createTypeScope,
  nestTypeScopeInManager,
  findTypeScopes,
  getTypeVariableNames,
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  TypeScope,
  ScopeManager,
  createTypeScope,
  nestTypeScopeInManager,
  findTypeScopes,
  getTypeVariableNames,
} = require('../src/index.js');
const scopeManagerModule = require('@typescript-eslint/scope-manager');

// 1. TypeScope is exported by @typescript-eslint/scope-manager and instantiates with type ScopeType, upper scope, and block AST node
assert.strictEqual(typeof TypeScope, 'function', 'TypeScope constructor should be exported as a function');
assert.strictEqual(TypeScope, scopeManagerModule.TypeScope, 'TypeScope export must match package TypeScope export');

const sm1 = new ScopeManager({});
const globalNode1 = { type: 'Program', body: [] };
const globalScope1 = sm1.nestGlobalScope(globalNode1);
const interfaceNode1 = {
  type: 'TSInterfaceDeclaration',
  id: { type: 'Identifier', name: 'Item' },
  body: { type: 'TSInterfaceBody', body: [] },
};
const directScope = createTypeScope(sm1, globalScope1, interfaceNode1);

assert.strictEqual(directScope instanceof TypeScope, true, 'Instance should be an instanceof TypeScope');
assert.strictEqual(directScope.type, 'type', 'Scope type must be "type"');
assert.strictEqual(directScope.upper, globalScope1, 'TypeScope upper must point to the parent scope');
assert.strictEqual(directScope.block, interfaceNode1, 'TypeScope block must point to the interface AST node');
assert.strictEqual(directScope.isStrict, true, 'TypeScope should default to strict mode');

// 2. ScopeManager.nestTypeScope creates and registers a TypeScope within the active scope hierarchy
const sm2 = new ScopeManager({});
const globalNode2 = { type: 'Program', body: [] };
sm2.nestGlobalScope(globalNode2);
const typeAliasNode2 = {
  type: 'TSTypeAliasDeclaration',
  id: { type: 'Identifier', name: 'Identity' },
  typeAnnotation: { type: 'TSAnyKeyword' },
};

const nestedScope = nestTypeScopeInManager(sm2, typeAliasNode2);
assert.strictEqual(nestedScope instanceof TypeScope, true, 'nestedScope should be an instance of TypeScope');
assert.strictEqual(nestedScope.type, 'type', 'nestedScope type must be "type"');
assert.strictEqual(sm2.scopes.includes(nestedScope), true, 'ScopeManager scopes array must contain the TypeScope');
assert.strictEqual(sm2.acquire(typeAliasNode2), nestedScope, 'ScopeManager acquire must resolve the type alias node to the TypeScope');
assert.strictEqual(sm2.currentScope, nestedScope, 'ScopeManager currentScope should be updated to the TypeScope');

// 3. analyze produces a TypeScope for generic TSTypeAliasDeclaration with its type parameters recorded in variables and set
const astTypeAlias = {
  type: 'Program',
  sourceType: 'module',
  body: [
    {
      type: 'TSTypeAliasDeclaration',
      id: { type: 'Identifier', name: 'Container' },
      typeParameters: {
        type: 'TSTypeParameterDeclaration',
        params: [
          {
            type: 'TSTypeParameter',
            name: { type: 'Identifier', name: 'T' },
          },
        ],
      },
      typeAnnotation: {
        type: 'TSTypeReference',
        typeName: { type: 'Identifier', name: 'T' },
      },
    },
  ],
};

const typeScopesFromAlias = findTypeScopes(astTypeAlias);
assert.strictEqual(typeScopesFromAlias.length, 1, 'Exactly one TypeScope should be found in type alias AST');
const [typeScopeAlias] = typeScopesFromAlias;

assert.strictEqual(typeScopeAlias.type, 'type', 'Scope type must be "type"');
assert.strictEqual(typeScopeAlias.block.type, 'TSTypeAliasDeclaration', 'Scope block must be TSTypeAliasDeclaration');
assert.strictEqual(typeScopeAlias.set.has('T'), true, 'TypeScope set must contain the type parameter "T"');
const aliasNames = getTypeVariableNames(typeScopeAlias);
assert.deepStrictEqual(aliasNames, ['T'], 'Variables declared in TypeScope must match type parameter name');

const tVariable = typeScopeAlias.set.get('T');
assert.strictEqual(tVariable.name, 'T');
assert.strictEqual(tVariable.defs[0].type, 'Type', 'Variable definition type should be Type');
assert.strictEqual(tVariable.references.length, 1, 'Variable should resolve the type reference in type annotation');
assert.strictEqual(tVariable.references[0].identifier.name, 'T');

// 4. analyze produces a TypeScope for generic TSInterfaceDeclaration with its type parameters recorded in variables and resolved in interface body
const astInterface = {
  type: 'Program',
  sourceType: 'module',
  body: [
    {
      type: 'TSInterfaceDeclaration',
      id: { type: 'Identifier', name: 'KeyValuePair' },
      typeParameters: {
        type: 'TSTypeParameterDeclaration',
        params: [
          {
            type: 'TSTypeParameter',
            name: { type: 'Identifier', name: 'K' },
          },
          {
            type: 'TSTypeParameter',
            name: { type: 'Identifier', name: 'V' },
          },
        ],
      },
      extends: [],
      body: {
        type: 'TSInterfaceBody',
        body: [
          {
            type: 'TSPropertySignature',
            key: { type: 'Identifier', name: 'key' },
            typeAnnotation: {
              type: 'TSTypeAnnotation',
              typeAnnotation: {
                type: 'TSTypeReference',
                typeName: { type: 'Identifier', name: 'K' },
              },
            },
          },
          {
            type: 'TSPropertySignature',
            key: { type: 'Identifier', name: 'value' },
            typeAnnotation: {
              type: 'TSTypeAnnotation',
              typeAnnotation: {
                type: 'TSTypeReference',
                typeName: { type: 'Identifier', name: 'V' },
              },
            },
          },
        ],
      },
    },
  ],
};

const interfaceScopes = findTypeScopes(astInterface);
assert.strictEqual(interfaceScopes.length, 1, 'Exactly one TypeScope should be found in interface AST');
const [typeScopeInterface] = interfaceScopes;

assert.strictEqual(typeScopeInterface.type, 'type', 'Scope type must be "type"');
assert.strictEqual(typeScopeInterface.block.type, 'TSInterfaceDeclaration', 'Scope block must be TSInterfaceDeclaration');
assert.strictEqual(typeScopeInterface.set.has('K'), true, 'TypeScope set must contain type parameter "K"');
assert.strictEqual(typeScopeInterface.set.has('V'), true, 'TypeScope set must contain type parameter "V"');
const interfaceNames = getTypeVariableNames(typeScopeInterface);
assert.deepStrictEqual(interfaceNames, ['K', 'V'], 'Variables in TypeScope must match generic parameters');

const kVar = typeScopeInterface.set.get('K');
const vVar = typeScopeInterface.set.get('V');
assert.strictEqual(kVar.references.length, 1, 'Reference to K in interface body must be resolved');
assert.strictEqual(vVar.references.length, 1, 'Reference to V in interface body must be resolved');

// 5. TypeScope confines type parameters so they cannot be resolved outside their declaration scope
const astIsolation = {
  type: 'Program',
  sourceType: 'module',
  body: [
    {
      type: 'TSTypeAliasDeclaration',
      id: { type: 'Identifier', name: 'ScopedBox' },
      typeParameters: {
        type: 'TSTypeParameterDeclaration',
        params: [
          {
            type: 'TSTypeParameter',
            name: { type: 'Identifier', name: 'Param' },
          },
        ],
      },
      typeAnnotation: {
        type: 'TSTypeReference',
        typeName: { type: 'Identifier', name: 'Param' },
      },
    },
    {
      type: 'TSTypeAliasDeclaration',
      id: { type: 'Identifier', name: 'Unrelated' },
      typeAnnotation: {
        type: 'TSTypeReference',
        typeName: { type: 'Identifier', name: 'Param' },
      },
    },
  ],
};

const isolationScopeManager = scopeManagerModule.analyze(astIsolation);
const [scopedBoxTypeScope] = isolationScopeManager.scopes.filter((s) => s instanceof TypeScope);
assert.ok(scopedBoxTypeScope, 'ScopedBox TypeScope must be present');
assert.strictEqual(scopedBoxTypeScope.set.has('Param'), true, 'Param should be defined in ScopedBox TypeScope');
assert.strictEqual(scopedBoxTypeScope.set.get('Param').references.length, 1, 'Reference inside ScopedBox must resolve to Param');

const unresolvedGlobalRefs = isolationScopeManager.scopes[0].through.map((ref) => ref.identifier.name);
assert.strictEqual(
  unresolvedGlobalRefs.includes('Param'),
  true,
  'Outer reference to Param must remain unresolved and bubble through the global scope',
);

console.log('All TypeScope contract assertions passed successfully.');

Seeder de origen

anónimo