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 (
.tsor.tsxfiles)
Basic Usage
To check TypeScript types in your project, open the terminal in the root directory of your Native Desktop project and run:- Load TypeScript configuration from
tsconfig.json - Analyze all TypeScript files in your project
- Check for type errors and inconsistencies
- Report any type-related issues
- Exit with an appropriate status code
What Gets Checked
By default, the types command checks:- All TypeScript files (
.ts,.tsx) - Type definitions (
.d.tsfiles) - Files in the
src/directory - Files specified in
tsconfig.jsoninclude patterns
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 thetsconfig.json file generated by native-desktop create. Here’s an example configuration:
TypeScript Compiler Options
Common compiler options that affect type checking:- Strict Checks
- Error Detection
- Module Resolution
- Other Options
- strict: Enable all strict type-checking options
- noImplicitAny: Error on expressions with implied
anytype - strictNullChecks: Enable strict null checking
- strictFunctionTypes: Enable strict checking of function types
- strictBindCallApply: Enable strict checking of
bind,call, andapply - strictPropertyInitialization: Ensure class properties are initialized
Common Type Errors
Type Mismatch
Type Mismatch
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.Property Does Not Exist
Property Does Not Exist
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.Implicit Any
Implicit Any
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.Null or Undefined Error
Null or Undefined Error
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.Missing Return Statement
Missing Return Statement
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
TypeScript Configuration Not Found
TypeScript Configuration Not Found
Error:
Cannot find tsconfig.jsonSolution: Ensure the configuration file exists in your project root.Cannot Find Module
Cannot Find Module
Error:
Cannot find module 'xyz'Solution: Install missing type definitions or dependencies.Too Many Type Errors
Too Many Type Errors
Error: Overwhelmed by type errors in a new projectSolution: Fix errors gradually or adjust strictness settings temporarily.
Type Definitions Conflict
Type Definitions Conflict
Error: Conflicting type definitionsSolution: Check for duplicate type packages or version mismatches.
Out of Memory Error
Out of Memory Error
Error: Update
JavaScript heap out of memorySolution: Increase Node.js memory limit or exclude large directories.tsconfig.json:Customizing Type Checking
You can customize TypeScript’s behavior intsconfig.json:
IDE Integration
Most modern IDEs provide built-in TypeScript support:Visual Studio Code
TypeScript support is built-in. Configure insettings.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: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:- Relaxed (Not Recommended)
- Standard
- Strict (Recommended)
Command Comparison
| Command | Purpose | Auto-Fix | Type Checking |
|---|---|---|---|
native-desktop types | Check TypeScript types | ❌ No | ✅ Yes |
native-desktop lint | Check code quality | ⚠️ Limited | ❌ No |
native-desktop fmt | Format code style | ✅ Yes | ❌ No |
Use all three commands together for comprehensive code quality: types for type safety, lint for code quality, and fmt for consistent formatting.