TypeScript Configuration
Relevant source files This document provides a detailed explanation of the TypeScript configuration in@ui8kit/core, covering compilation settings, type generation, path aliases, and module resolution. The configuration is defined in tsconfig.json1-26 and integrates with the build system documented in Build System.
For information about the distribution artifacts generated by TypeScript compilation, see Package Structure. For details on how types are used in component APIs, see API Reference.
Configuration Overview
The TypeScript configuration serves three primary functions: compiling source code fromsrc/ to ES2022 modules in dist/, generating type declaration files (.d.ts) for IDE autocomplete and type checking, and establishing path aliases for clean imports.
Diagram: TypeScript Compilation Pipeline
Compilation Target Settings
The configuration targets modern JavaScript environments with ES2022 output, avoiding transpilation of recent language features while maintaining broad compatibility. Compilation Settings Table| Setting | Value | Purpose | Line Reference |
|---|---|---|---|
target | ES2022 | Compile to ECMAScript 2022 syntax | tsconfig.json5 |
module | ES2022 | Use ES2022 module system | tsconfig.json6 |
lib | ["DOM", "ESNext", "ES2022"] | Include DOM APIs and latest JavaScript features | tsconfig.json14 |
jsx | react-jsx | Use React 17+ automatic JSX runtime | tsconfig.json15 |
moduleResolution | Bundler | Modern bundler-compatible resolution | tsconfig.json7 |
Target: ES2022
Thetarget: "ES2022" setting tsconfig.json5 compiles TypeScript to ECMAScript 2022, which includes:
- Top-level await
- Class fields and private methods
- Static initialization blocks
- Error cause property
at()method for arrays
Module System: ES2022
Themodule: "ES2022" setting tsconfig.json6 generates ES modules with .js extensions, enabling tree-shaking in consumer applications. This aligns with the "type": "module" declaration in package.json8
Module Resolution: Bundler
ThemoduleResolution: "Bundler" setting tsconfig.json7 uses bundler-specific resolution that supports:
- Extensionless imports (
import { Button } from "./Button") - Package exports field resolution
- Conditional exports for different environments
- Subpath patterns
Type System Configuration
The configuration enables all strict type checking options and generates declaration files for IDE integration. Type System Settings Table| Setting | Value | Purpose | Line Reference |
|---|---|---|---|
strict | true | Enable all strict type checks | tsconfig.json8 |
declaration | true | Generate .d.ts type declarations | tsconfig.json17 |
declarationDir | ./dist | Output directory for type definitions | tsconfig.json18 |
composite | true | Enable project references | tsconfig.json16 |
skipLibCheck | true | Skip type checking of declaration files | tsconfig.json10 |
esModuleInterop | true | Enable CommonJS/ES module interoperability | tsconfig.json9 |
Strict Mode
Thestrict: true flag tsconfig.json8 enables all strict type checking options:
strictNullChecks: Null and undefined are not assignable to other typesstrictFunctionTypes: Function parameters are checked contravariantlystrictBindCallApply: Type-checkbind,call, andapplymethodsstrictPropertyInitialization: Class properties must be initializednoImplicitAny: Variables must have explicit typesnoImplicitThis:thisexpressions require explicit typealwaysStrict: Parse in strict mode and emit"use strict"
Declaration Generation
Thedeclaration: true setting tsconfig.json17 generates .d.ts files alongside compiled JavaScript. These type definitions:
- Enable IDE autocomplete for all exported components
- Provide inline documentation from JSDoc comments
- Support type checking in consumer TypeScript projects
- Power the
"types": "./dist/index.d.ts"entry in package.json32
Composite Projects
Thecomposite: true flag tsconfig.json16 enables TypeScript project references, which:
- Allow faster incremental builds
- Enable dependency graphs between TypeScript projects
- Support monorepo architectures documented in SUBMODULE_GUIDE.md
Path Alias Configuration
Path aliases enable clean imports using@/ prefix and @ui8kit/core package reference.
Path Alias Settings
Base URL
ThebaseUrl: "." setting tsconfig.json20 establishes the project root as the base for all non-relative imports. This enables path resolution relative to the repository root.
Path Mappings
Thepaths object tsconfig.json21-24 defines two alias patterns:
Alias Table
| Alias Pattern | Resolves To | Usage Example | Purpose |
|---|---|---|---|
@/* | ./src/* | import { Button } from "@/components/ui/Button" | Internal source imports |
@ui8kit/core | ./src/index | import { Button } from "@ui8kit/core" | Main package entry point |
Internal Imports: @/*
The @/* alias maps to ./src/* tsconfig.json22 enabling imports like:
import { Block } from "@/core/ui/Block"import { spacingVariants } from "@/core/variants/spacing"import { ThemeProvider } from "@/themes/providers/ThemeProvider"
../../../core/ui/Block) and makes refactoring safer.
Package Entry Point: @ui8kit/core
The @ui8kit/core alias maps to ./src/index tsconfig.json23 allowing internal files to import from the package as consumers would. This is useful in:
- Example code and documentation
- Testing component composition
- Verifying the public API surface
Build Output Configuration
The configuration controls where compiled files and type definitions are written. Output Settings Table| Setting | Value | Purpose | Line Reference |
|---|---|---|---|
rootDir | src | Source directory root | tsconfig.json13 |
outDir | ./dist | Compiled JavaScript output | tsconfig.json19 |
declarationDir | ./dist | Type definition output | tsconfig.json18 |
Root Directory
TherootDir: "src" setting tsconfig.json13 establishes src/ as the root for compilation. This ensures the output directory structure mirrors the source:
Output Directory
TheoutDir: "./dist" setting tsconfig.json19 writes compiled JavaScript to dist/. This directory is:
- Included in NPM package via
"files": ["dist/**/*"]in package.json39-43 - Referenced by
"main": "./dist/index.js"in package.json31 - Excluded from version control via
.gitignore - Generated by the
npm run buildscript in package.json22
Declaration Directory
ThedeclarationDir: "./dist" setting tsconfig.json18 writes .d.ts files alongside .js files in the same directory structure. This colocation:
- Simplifies package distribution (single
dist/folder) - Matches consumer expectations for type locations
- Enables the
"types": "./dist/index.d.ts"entry in package.json32
Include and Exclude Patterns
The configuration specifies which files to compile and which to ignore. File Pattern SettingsInclude Pattern
Theinclude: ["./src"] setting tsconfig.json2 compiles all TypeScript files within the src/ directory:
src/**/*.ts- All TypeScript filessrc/**/*.tsx- All React component filessrc/**/*.json- JSON modules (viaresolveJsonModule: true)
- Core primitives in
src/core/ui/ - Variant definitions in
src/core/variants/ - UI components in
src/components/ui/ - Layout templates in
src/layouts/ - Theme system in
src/themes/ - Registry metadata in
src/registry.json
Exclude Pattern
Theexclude: ["./lib", "./dist"] setting tsconfig.json3 prevents compilation of:
./lib/- Generated artifacts likecore-classes.jsondocumented in Build System./dist/- Previously compiled output to avoid recursive compilation
Special Compiler Options
Several additional options configure TypeScript’s behavior for specific use cases. Special Options Table| Setting | Value | Purpose | Line Reference |
|---|---|---|---|
types | ["bun-types"] | Include Bun runtime types | tsconfig.json11 |
resolveJsonModule | true | Allow importing JSON files | tsconfig.json12 |
esModuleInterop | true | Enable CommonJS interop | tsconfig.json9 |
skipLibCheck | true | Skip library type checking | tsconfig.json10 |
sideEffects | false (package.json) | Enable tree-shaking | package.json30 |
Bun Runtime Types
Thetypes: ["bun-types"] setting tsconfig.json11 includes type definitions for the Bun runtime. This enables:
- Type checking for Bun-specific APIs
- Support for
buncommands in scripts likebunx buildy-ui@latest scanin package.json26 - Development with Bun’s fast TypeScript transpiler
bun-types dependency is declared in package.json62
JSON Module Resolution
TheresolveJsonModule: true setting tsconfig.json12 allows importing JSON files as typed modules:
src/registry.json throughout the codebase, as documented in Component Registry.
CommonJS Interoperability
TheesModuleInterop: true setting tsconfig.json9 enables seamless imports of CommonJS modules in ES module syntax:
class-variance-authority and clsx declared in package.json48-53
Library Type Checking
TheskipLibCheck: true setting tsconfig.json10 skips type checking of .d.ts files in node_modules/. This:
- Speeds up compilation significantly
- Avoids errors from incompatible library types
- Focuses type checking on project source code
Integration with Build Scripts
The TypeScript configuration integrates with several build scripts defined inpackage.json.
Build Script Integration Diagram
Build Script
Thenpm run build command package.json22 executes:
- Reads all settings from
tsconfig.json - Compiles
src/**/*.tsandsrc/**/*.tsxtodist/ - Generates
.d.tstype definitions indist/ - Applies path alias transformations
- Enables strict type checking
- Exits with code 1 if any type errors are found
Type Check Script
Thenpm run type-check command package.json23 executes:
--noEmit flag:
- Performs full type checking without generating files
- Validates types in local development
- Runs faster than full compilation
- Useful in CI/CD pipelines before deployment
Lint Script Integration
Thenpm run lint command package.json24 runs ESLint on TypeScript files:
- Understanding path aliases defined in
tsconfig.json - Parsing TypeScript syntax (
.ts,.tsxextensions) - Accessing type information for advanced linting rules
npm run lint:fix variant package.json25 automatically fixes fixable issues.
Sources: package.json22-25 tsconfig.json1-26
Summary
The TypeScript configuration in@ui8kit/core establishes a modern, type-safe build pipeline:
- Compilation Target: ES2022 modules with bundler-friendly resolution
- Type Generation: Full declaration files (
.d.ts) for IDE integration - Strict Checking: All strict mode options enabled for type safety
- Path Aliases:
@/*for internal imports,@ui8kit/corefor package reference - Output Structure:
dist/directory mirroringsrc/structure - JSON Support: Import registry metadata as typed modules
- Build Integration: Scripts for compilation, type checking, and linting