TypeScript Starter - A starter template with TypeScript rules, tooling, and configuration for Node.js projects.
// β
ENFORCED: Strict mode with comprehensive type checking
// β
ENFORCED: No implicit any types
// β
ENFORCED: No unused variables or parameters
// β
ENFORCED: All code paths must return
// β
ENFORCED: Explicit type annotations required
// β
ENFORCED: No unreachable code
// β
ENFORCED: Exact optional property types
// β
ENFORCED: No unchecked indexed access
// β This will fail:
function badFunction(input) { // implicit any
if (condition) return value // not all paths return
const unused = "never used" // unused variable
}
// β
This passes:
function goodFunction: (input: string) => string = (input: string): string => {
if (condition) {
return value
}
return defaultValue
}// β
ENFORCED: Single quotes, no semicolons
// β
ENFORCED: 2-space indentation
// β
ENFORCED: No trailing commas
// β
ENFORCED: Required curly braces
// β
ENFORCED: Spaces inside object braces
// β
ENFORCED: No spaces inside array brackets
// β
ENFORCED: Consistent naming conventions
// β This will fail:
const obj = {a: 1, b: 2,}; // trailing comma
const arr = [ 1, 2, 3 ]; // spaces in array
if(condition) return value; // no curly braces, semicolon
// β
This passes:
const obj = { a: 1, b: 2 }
const arr = [1, 2, 3]
if (condition) {
return value
}// β
ENFORCED: Prefer const over let/var
// β
ENFORCED: Arrow functions for callbacks
// β
ENFORCED: Template literals over concatenation
// β
ENFORCED: Object destructuring where applicable
// β
ENFORCED: No inline comments
// β
ENFORCED: Cognitive complexity β€ 15
// β
ENFORCED: No duplicate code
// β
ENFORCED: Prefer immediate returns
// β This will fail:
var oldWay = "string" + variable; // var, concatenation
function callback() { return value; } // function instead of arrow
// inline comment // inline comment
// β
This passes:
const newWay = `string ${variable}`
const callback = () => value
// Block comment for complex logic// β
ENFORCED: No duplicate strings
// β
ENFORCED: No identical functions
// β
ENFORCED: No redundant boolean expressions
// β
ENFORCED: Prefer immediate returns
// β
ENFORCED: No one-iteration loops
// β
ENFORCED: No unused variables
// β
ENFORCED: No unreachable code
// β This will fail:
const message = "Hello"
const greeting = "Hello" // duplicate string
if (condition === true) { // redundant boolean
return value
}
// β
This passes:
const MESSAGES = {
GREETING: "Hello"
} as const
if (condition) {
return value
}# Clone and start coding
git clone https://github.com/NeaByteLab/TypeScript-Starter.git my-project
cd my-project
npm install
npm run dev# Development
npm run dev # TypeScript watch mode
npm run build # Build for production
npm run clean # Clean build directory
# Code Quality
npm run lint # ESLint with strict rules
npm run lint:fix # Auto-fix ESLint violations
npm run format # Prettier formatting
npm run type-check # TypeScript type checking
# Testing
npm run test # Run tests with Jest
npm run test:watch # Watch mode for TDD
npm run test:coverage # Run tests with coverage
# Documentation
npm run docs # Generate TypeDoc documentation
# Quality Assurance
npm run check-all # Run all checksTypeScript-Starter/
βββ src/ # Source code
β βββ types/ # Type definitions
β β βββ index.ts # Common types: ConfigOptions, Result<T>, EventHandler, etc.
β βββ utils/ # Utility functions
β β βββ index.ts # Helper functions: isNotEmpty, createSuccessResult, etc.
β βββ index.ts # Main entry point - exports all public APIs
βββ tests/ # Test files
β βββ setup.ts # Jest test setup and global configurations
β βββ example.test.ts # Test suite for all functions
βββ examples/ # Example usage
β βββ basic-usage.ts # Usage examples with async support
βββ dist/ # Build output (ESM + type definitions)
βββ docs/ # Auto-generated TypeDoc documentation
βββ coverage/ # Test coverage reports (HTML + LCOV)
βββ Configuration Files # Strict rules enforced
βββ tsconfig.json # TypeScript configuration (all strict options enabled)
βββ eslint.config.js # ESLint configuration (200+ rules)
βββ jest.config.js # Jest testing configuration with TypeScript
βββ package.json # Dependencies and scripts
// Configuration options interface
export interface ConfigOptions {
readonly debug: boolean
readonly timeout: number
readonly retries: number
}
// Result type for operations (success/error handling)
export type Result<T> = {
readonly success: boolean
readonly data?: T
readonly error?: string
}
// Event handler type
export type EventHandler<T = unknown> = (event: T) => void
// Async operation type
export type AsyncOperation<T> = () => Promise<T>
// Validation function type
export type Validator<T> = (value: T) => boolean// String validation
export const isNotEmpty: (value: string) => boolean
// Result constructors
export const createSuccessResult: <T>(data: T) => Result<T>
export const createErrorResult: <T>(error: string) => Result<T>
// Async utilities
export const delay: (ms: number) => Promise<void>// Example function (demonstrates strict typing)
export const exampleFunction: (input: string) => string
// Example class (demonstrates OOP with strict rules)
export class ExampleClass {
constructor(value: string)
public getValue(): string
public setValue(newValue: string): void
}import {
exampleFunction,
ExampleClass,
isNotEmpty,
createSuccessResult,
createErrorResult,
delay,
type ConfigOptions,
type Result
} from 'typescript-starter'
// Function usage
const result = exampleFunction('hello world')
console.log(result) // "HELLO WORLD"
// Class usage
const instance = new ExampleClass('test value')
console.log(instance.getValue()) // "TEST VALUE"
// Utility usage
console.log(isNotEmpty('valid')) // true
console.log(isNotEmpty('')) // false
const success = createSuccessResult({ message: 'OK' })
const error = createErrorResult<string>('Failed')
// Async usage
await delay(1000)
console.log('Delayed execution')// β Too complex (will fail)
function complexFunction(input: string): string {
if (condition1) {
if (condition2) {
if (condition3) {
if (condition4) {
if (condition5) {
return "too complex"
}
}
}
}
}
return "default"
}
// β
Simple and clear (passes)
function simpleFunction(input: string): string {
if (!condition1) return "default"
if (!condition2) return "default"
if (!condition3) return "default"
return "result"
}// β These will fail compilation
function badFunction(input) { // implicit any
if (condition) return value // not all paths return
const unused = "never used" // unused variable
}
// β
These pass strict checking
function goodFunction(input: string): string {
if (condition) {
return value
}
return defaultValue
}// tests/example.test.ts
import { exampleFunction, ExampleClass } from '@/index'
describe('exampleFunction', () => {
it('should convert string to uppercase', () => {
const result = exampleFunction('test')
expect(result).toBe('TEST')
})
})
describe('ExampleClass', () => {
let instance: ExampleClass
beforeEach(() => {
instance = new ExampleClass('initial')
})
it('should set and get values correctly', () => {
instance.setValue('new value')
expect(instance.getValue()).toBe('NEW VALUE')
})
})- Lines: 80% minimum
- Functions: 100% for public APIs
- Branches: 80% minimum
- Statements: 80% minimum
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage/**
* Example function demonstrating strict rules
* @param input - Input string to process
* @returns Processed string in uppercase
*/
export const exampleFunction: (input: string) => string = (input: string): string => {
return input.toUpperCase()
}
/**
* Example class with strict typing
*/
export class ExampleClass {
private value: string
constructor(initialValue: string) {
this.value = initialValue.toUpperCase()
}
/**
* Get the current value
* @returns The current value in uppercase
*/
public getValue(): string {
return this.value
}
/**
* Set a new value
* @param newValue - The new value to set
*/
public setValue(newValue: string): void {
this.value = newValue.toUpperCase()
}
}// β Relative imports (messy)
import { utils } from '../../../utils/helper'
// β
Path aliases (clean)
import { utils } from '@/utils/helper'
import { types } from '@types/common'
import { helpers } from '@utils/helpers'@/*βsrc/*(main source directory)@types/*βsrc/types/*(type definitions)@utils/*βsrc/utils/*(utility functions)
npm run dev # Rules are checkednpm run test:watch # TDD approachnpm run check-all # All rules checkednpm run build # Production build with minification
npm run docs # Generate TypeDoc documentation
npm run clean # Clean build directoryMIT License - see LICENSE file for details.