Skip to main content
The types command runs TypeScript’s type checker on your Native Desktop project to validate type safety, catch type errors, and ensure your code adheres to TypeScript’s type system without emitting any output files.

Prerequisites

Before running the types command, ensure:
  • Your project has been created using native-desktop create
  • All dependencies are installed (npm install)
  • TypeScript configuration exists (tsconfig.json)
  • Your project uses TypeScript (.ts or .tsx files)

Basic Usage

To check TypeScript types in your project, open the terminal in the root directory of your Native Desktop project and run:
This command will:
  1. Load TypeScript configuration from tsconfig.json
  2. Analyze all TypeScript files in your project
  3. Check for type errors and inconsistencies
  4. Report any type-related issues
  5. Exit with an appropriate status code

What Gets Checked

By default, the types command checks:
  • All TypeScript files (.ts, .tsx)
  • Type definitions (.d.ts files)
  • Files in the src/ directory
  • Files specified in tsconfig.json include patterns
Files and directories specified in tsconfig.json exclude patterns are automatically skipped.

Output Examples

Successful Type Check (No Errors)

With Type Errors

With Warnings

TypeScript Configuration

The types command uses the tsconfig.json file generated by native-desktop create. Here’s an example configuration:

TypeScript Compiler Options

Common compiler options that affect type checking:
  • strict: Enable all strict type-checking options
  • noImplicitAny: Error on expressions with implied any type
  • strictNullChecks: Enable strict null checking
  • strictFunctionTypes: Enable strict checking of function types
  • strictBindCallApply: Enable strict checking of bind, call, and apply
  • strictPropertyInitialization: Ensure class properties are initialized

Common Type Errors

Error: Type 'X' is not assignable to type 'Y'Cause: You’re trying to assign a value of one type to a variable of another type.Solution: Ensure the types match or use type assertions/conversions.
Error: Property 'X' does not exist on type 'Y'Cause: You’re accessing a property that doesn’t exist on the object’s type.Solution: Add the property to the type definition or use optional chaining.
Error: Parameter 'X' implicitly has an 'any' typeCause: TypeScript can’t infer the type and no explicit type is provided.Solution: Add explicit type annotations.
Error: Object is possibly 'null' or 'undefined'Cause: You’re accessing a property on a value that might be null or undefined.Solution: Add null checks or use optional chaining.
Error: Function lacks ending return statementCause: A function with a non-void return type doesn’t return a value in all code paths.Solution: Ensure all code paths return a value.

Integration with Development Workflow

Pre-Commit Hook

Add type checking to your pre-commit hooks:

CI/CD Pipeline

Include type checking in your continuous integration:

npm Scripts

Add type checking to your package.json scripts:

Exit Codes

The types command uses standard exit codes for CI/CD integration:
  • 0: No type errors found
  • 1: Type errors found

Common Issues

Error: Cannot find tsconfig.jsonSolution: Ensure the configuration file exists in your project root.
Error: Cannot find module 'xyz'Solution: Install missing type definitions or dependencies.
Error: Overwhelmed by type errors in a new projectSolution: Fix errors gradually or adjust strictness settings temporarily.
Error: Conflicting type definitionsSolution: Check for duplicate type packages or version mismatches.
Error: JavaScript heap out of memorySolution: Increase Node.js memory limit or exclude large directories.
Update tsconfig.json:

Customizing Type Checking

You can customize TypeScript’s behavior in tsconfig.json:

IDE Integration

Most modern IDEs provide built-in TypeScript support:

Visual Studio Code

TypeScript support is built-in. Configure in settings.json:

WebStorm / IntelliJ IDEA

TypeScript support is built-in and enabled by default. Settings → Languages & Frameworks → TypeScript
  • Enable TypeScript Language Service
  • Use project’s TypeScript version

Type Checking Specific Files

While the CLI command checks the entire project, you can check specific files using tsc directly:

Watch Mode

For continuous type checking during development, use TypeScript’s watch mode:
This will continuously check types as you make changes to your code.

Best Practices

Enable Strict Mode

Use "strict": true for maximum type safety and error prevention.

Type Everything

Add explicit type annotations, especially for function parameters and return types.

Check Regularly

Run type checking frequently during development to catch errors early.

Fix Incrementally

When facing many errors, fix them incrementally rather than all at once.

Type Safety Levels

Different levels of type strictness you can configure:

Command Comparison

Use all three commands together for comprehensive code quality: types for type safety, lint for code quality, and fmt for consistent formatting.

Development Workflow

Recommended workflow for type-safe development:

Performance Optimization

For large projects, optimize type checking performance: