@hyperfrontend/project-scope/tech/types

types

Type-system detectors covering the typing approaches found in JavaScript codebases.

Covers TypeScript, Flow, and JSDoc-typed JavaScript. typescriptDetector, flowDetector, and jsdocDetector each follow the shared TypeSystemDetector contract; detectTypeSystems runs them all and returns the aggregate TypeSystemDetection[]. Allows downstream tooling to make type-system-aware decisions without hard-coding "if tsconfig.json exists" checks.

API Reference

ƒ Functions

§function

detectTypeSystems(projectPath: string, packageJson?: PackageJson): TypeSystemDetection[]

Detect all type systems in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

TypeSystemDetection[]
Array of detected type systems, sorted by confidence

Example

Detecting all type systems

import { detectTypeSystems } from '@hyperfrontend/project-scope'

const typeSystems = detectTypeSystems('./my-project')
// => [
//   { id: 'typescript', name: 'TypeScript', version: '5.3.0', strictMode: true, confidence: 95, ... },
//   { id: 'jsdoc', name: 'JSDoc', confidence: 40, ... }
// ]

const primary = typeSystems[0]?.name ?? 'None'
console.log(`Primary type system: ${primary}`)
§function

flowDetector(projectPath: string, packageJson?: PackageJson): TypeSystemDetection

Detect Flow in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

TypeSystemDetection
Detection result or null if not detected

Example

Detecting Flow type system

import { flowDetector } from '@hyperfrontend/project-scope'

const result = flowDetector('./my-project')
if (result) {
  console.log(`Flow ${result.version} with config: ${result.configPath}`)
  // => "Flow 0.232.0 with config: .flowconfig"
}
§function

jsdocDetector(projectPath: string, packageJson?: PackageJson): TypeSystemDetection

Detect JSDoc type annotations in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

TypeSystemDetection
Detection result or null if not detected

Example

Detecting JSDoc type annotations

import { jsdocDetector } from '@hyperfrontend/project-scope'

const result = jsdocDetector('./my-project')
if (result) {
  console.log('JSDoc types detected')
  console.log('Sources:', result.detectedFrom.map(s => s.path ?? s.field))
  // => "Sources: ['jsconfig.json', 'src/utils.js (JSDoc annotations)']"
}
§function

typescriptDetector(projectPath: string, packageJson?: PackageJson): TypeSystemDetection

Detect TypeScript in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

TypeSystemDetection
Detection result or null if not detected

Example

Detecting TypeScript

import { typescriptDetector } from '@hyperfrontend/project-scope'

const result = typescriptDetector('./my-project')
if (result) {
  console.log(`TypeScript ${result.version}`)
  console.log(`Strict mode: ${result.strictMode ?? 'unknown'}`)
  // => "TypeScript 5.3.0"
  // => "Strict mode: true"
}

Interfaces

§interface

TypeSystemDetection

Type system detection result.

Properties

§confidence:number
Detection confidence (0-100)
§configPath?:string
Config file path
§detectedFrom:DetectionSource[]
Detection sources
§id:"typescript" | "flow" | "jsdoc"
Type system identifier
§name:string
Human-readable name
§strictMode?:boolean
Strict mode enabled
§version?:string
Detected version
§interface

TypeSystemDetector

Type system detector interface.

Properties

§id:"typescript" | "flow" | "jsdoc"
Type system identifier
§name:string
Human-readable name

Variables

§type

typeSystemDetectors

All type system detectors