Why Share Solutions?
- Help Others Learn - Your approach might be clearer or more elegant than others
- Get Feedback - Learn alternative approaches and improve your skills
- Build Your Profile - Showcase your TypeScript expertise
- Contribute to Learning - Be part of the community knowledge base
How to Share Your Solution
Search for Existing Solutions
Before posting, search for similar solutions that may already be shared for your challenge.You can:
- Browse existing issues with the
answerlabel - Use GitHub search:
is:issue label:answer "challenge-number" - Check the challenge’s solutions page at
https://tsch.js.org/[number]/solutions
- Give it a thumbs up 👍
- Add your thoughts in the comments
- Share variations or improvements
Open an Answer Issue
If your solution offers something unique, create a new issue:
- Go to New Issue
- Select the “Answers” template
-
Use the title format:
[challenge-number] - [Challenge Name]Example:4 - Pickor189 - Awaited
Write Your Solution
Share your solution with the community. Include:Your Code:Optional but Helpful:
- Explanation - How does your solution work?
- Key Concepts - What TypeScript features did you use?
- Tradeoffs - Are there limitations or edge cases?
- Learning Points - What did you learn solving this?
Solution Template
Here’s a good template for sharing solutions:Explanation
[Explain how your solution works] Key concepts:K extends keyof T- Constrains K to be keys of T[P in K]- Mapped type iterating over KT[P]- Index access to get property type
Why This Works
[Explain the reasoning behind your approach]Alternative Approaches
[Optional: mention other ways to solve this]Explanation
This solution uses TypeScript’s mapped types to create a new type by iterating over the keys inK and picking the corresponding properties from T.
How it works:
-
K extends keyof T- This constraint ensures that K can only contain keys that exist in T. This gives us type safety and prevents picking non-existent properties. -
[P in K]- This is a mapped type that iterates over each key in the union K, binding each key to the variable P. -
T[P]- For each key P, we access the corresponding property type from T using indexed access.
- Generic type parameters (
<T, K>) - Generic constraints (
extends keyof T) - Mapped types (
[P in K]) - Indexed access types (
T[P])
What I Learned
This challenge taught me how to properly constrain generic type parameters. My first attempt didn’t includeextends keyof T and the test cases failed because TypeScript allowed picking invalid keys!
Best Practices
Common Solution Patterns
As you solve challenges, you’ll encounter these common TypeScript patterns:Mapped Types
Conditional Types
Template Literal Types
Recursive Types
Tuple Manipulation
Learning from Solutions
When reviewing others’ solutions:Try to Understand
Don’t just copy - understand why it works. Trace through the type transformations.
Solution Resources
Explore these resources for more solutions and explanations:- Official Solutions Page - Browse solutions for each challenge
- Video Explanations - Watch detailed walkthroughs
- ghaiklor’s Solutions - Comprehensive solution repository
- Type Gymnastics - Alternative solutions and approaches
Remember: There’s rarely one “correct” solution. Different approaches can teach different concepts. Share yours!
Community Guidelines
When sharing solutions:- Be respectful - Everyone is at a different learning stage
- Give credit - If your solution builds on someone else’s idea, mention them
- Stay constructive - Critique ideas, not people
- Help others - Answer questions about your solution
- Keep learning - Be open to better approaches
Getting Help
Stuck on a challenge? Here’s how to get help:- Read the challenge carefully - Make sure you understand what’s being asked
- Check existing solutions - See how others approached it
- Ask in Discord - The Type Challenges Discord is very active
- Open a help issue - Use the “Help” issue template
- Review TypeScript docs - Often the answer is in the TypeScript Handbook