Getting Started
What TypeScript version should I use?
What TypeScript version should I use?
How do I run the exercises?
How do I run the exercises?
Can I skip exercises?
Can I skip exercises?
- The documentation link at the bottom of the exercise
- The solution file (
index.solution.ts) for hints - The Tips & Best Practices page
Where can I see the solutions?
Where can I see the solutions?
index.solution.ts file showing the correct solution. However, try to solve each exercise on your own first before looking at the solution. The learning happens in the struggle!Type System Questions
Why can't I use 'any'?
Why can't I use 'any'?
any type disables TypeScript’s type checking, defeating the entire purpose of using TypeScript. It’s explicitly forbidden in these exercises (Rule #1).Using any is like telling TypeScript “I don’t care about types here,” which:- Removes type safety
- Hides potential bugs
- Makes refactoring dangerous
- Provides no IDE autocomplete
any, use:What's the difference between 'interface' and 'type'?
What's the difference between 'interface' and 'type'?
- Can be extended and implemented
- Can be reopened (declaration merging)
- Better for object-oriented patterns
- More flexible (unions, intersections, primitives)
- Cannot be reopened
- Better for complex type operations
What does 'unknown' mean and when should I use it?
What does 'unknown' mean and when should I use it?
unknown is the type-safe counterpart of any. It represents a value of unknown type, but unlike any, you must narrow it before using it.unknown when:- Receiving data from external sources (APIs, user input)
- You genuinely don’t know the type yet
- Writing generic utility functions
unknown with proper types as part of the solution.How do type guards work?
How do type guards work?
person is Admin syntax is a type predicate that tells TypeScript to narrow the type.What are utility types and why should I use them?
What are utility types and why should I use them?
- DRY (Don’t Repeat Yourself) principle
- Automatic updates when source types change
- Express intent clearly
- Leverage TypeScript’s built-in optimizations
Exercise-Specific Questions
Exercise 3: How do I check if a property exists on a union type?
Exercise 3: How do I check if a property exists on a union type?
in operator to check if a property exists on an object:Exercise 5: How do I make properties optional?
Exercise 5: How do I make properties optional?
Partial<T> utility type to make all properties optional:Omit to exclude specific properties:Exercise 7: How do I create a generic function with multiple type parameters?
Exercise 7: How do I create a generic function with multiple type parameters?
Exercise 8: How do I combine properties from multiple types?
Exercise 8: How do I combine properties from multiple types?
& operator:type field).Exercise 10: How do I promisify a callback-based function?
Exercise 10: How do I promisify a callback-based function?
Exercises 11-12: What are type declaration files (.d.ts)?
Exercises 11-12: What are type declaration files (.d.ts)?
.d.ts) provide type information for JavaScript code without affecting runtime behavior.When to use them:- Adding types to JavaScript libraries that lack them
- Declaring types for modules
- Extending existing type definitions
declare module tells TypeScript “this is what this module looks like” without implementing it.Read more: Declaration FilesExercise 13: How does module augmentation work?
Exercise 13: How does module augmentation work?
Exercise 14: What are function overloads?
Exercise 14: What are function overloads?
Exercise 15: How do I work with complex type transformations?
Exercise 15: How do I work with complex type transformations?
Troubleshooting
TypeScript is not recognizing my type changes
TypeScript is not recognizing my type changes
- Restart your IDE/editor - Sometimes the TypeScript language server needs a restart
- Clear the TypeScript cache - Delete
.tsbuildinfofiles if they exist - Check your tsconfig.json - Ensure the exercise files are included
- Verify imports - Make sure all types are properly imported
- Check for syntax errors - A syntax error can break type inference
I'm getting 'cannot find module' errors
I'm getting 'cannot find module' errors
-
Check that the type declaration file exists in the right location:
-
Verify your
tsconfig.jsonincludes the declarations directory: -
Make sure the module name in
declare moduleexactly matches the import:
My solution works but tests fail
My solution works but tests fail
-
Exact type match - TypeScript requires exact type matches.
string | numberis different fromnumber | stringin some contexts. - Read-only vs mutable - The tests might expect readonly properties or vice versa.
- Type narrowing - Make sure you’re properly narrowing types where needed.
- Return types - Verify your functions return exactly what the tests expect.
Error: 'X' is declared but never used
Error: 'X' is declared but never used
- Actually use the variable
- Prefix it with underscore:
_unusedVar - Adjust your ESLint/TSLint configuration
How do I debug complex type errors?
How do I debug complex type errors?
- Isolate the error - Comment out code until you find the exact line
- Check intermediate types - Hover over variables to see inferred types
- Create a type alias - Extract complex types to see them clearly:
- Use type assertions temporarily - To test hypotheses (remove afterward):
- Simplify the expression - Break complex types into smaller pieces
- Check the documentation - The link at the bottom of each exercise is specifically chosen to help
General TypeScript Questions
Should I use TypeScript in my projects?
Should I use TypeScript in my projects?
- Your codebase is medium to large
- Multiple developers work on the code
- You want better IDE autocomplete and refactoring
- The project will be maintained long-term
- You’re building a library or API
- Building a quick prototype or proof of concept
- The project is very small (< 100 lines)
- Your team is unfamiliar with types and learning would slow down critical work
What's the difference between TypeScript and JavaScript?
What's the difference between TypeScript and JavaScript?
- All valid JavaScript is valid TypeScript
- TypeScript adds optional static typing
- TypeScript code compiles to JavaScript
- Types are erased at runtime (no performance cost)
How does TypeScript's type system differ from other languages?
How does TypeScript's type system differ from other languages?
Where can I get help if I'm really stuck?
Where can I get help if I'm really stuck?
- TypeScript Discord - discord.gg/typescript - Active community
- Stack Overflow - Tag questions with
typescript - Reddit - r/typescript for discussions
- GitHub Issues - For bugs in the exercises themselves
- The documentation links - Each exercise links to relevant docs
- Read the error message carefully
- Check the Tips page
- Try the TypeScript Playground to isolate the issue
- Review the related documentation
- Share your code (use a playground link)
- Explain what you’ve tried
- Include the error message
- Mention which exercise you’re on
Contributing
I found a bug or typo. How do I report it?
I found a bug or typo. How do I report it?
- Check if the issue already exists: GitHub Issues
- Create a new issue with details
- Or submit a pull request with a fix
Can I add my own exercises?
Can I add my own exercises?
- Fork the repository
- Create a new exercise following the existing structure
- Include:
index.tswith the problemindex.solution.tswith the solutiontest.tswith tests- Comments explaining the exercise
- Links to relevant documentation
- Submit a pull request