TypeScript Assignments — Type. Refactor. Master.
Advance from type basics to production-ready patterns with topic-wise assignments. Each set includes 20 Basic, 20 Intermediate, and 10 Advanced questions so learners can practice deliberately and level up fast.
These five assignments cover the full TypeScript toolkit—from primitives & unions to generics, utility types, modules, and advanced typing.
Why practice with these assignments?
- Move beyond theory—compile, run, and refactor real TypeScript code with strict typing.
- Build professional habits: discriminated unions, safe unknown, never for exhaustiveness, utility types, and module hygiene.
- Prepare for interviews with interfaces, enums, generics, mapped/conditional types, and OOP patterns.
How it works
- Open any assignment and attempt questions in order: Basic → Intermediate → Advanced.
- Compile with tsc –noEmit while iterating; fix type errors before runtime.
- Add examples, edge cases, and comments for tricky types; refactor to cleaner models.
- Keep a short “what I learned” note per problem—this compounds quickly.
What you’ll achieve
- A clear mental model of types vs values, annotation vs inference, union/intersection/literal types, and any vs unknown.
- Fluency with arrays/tuples/enums, interfaces & type aliases, and generics.
- Practical OOP in TS: classes, access modifiers, abstract classes, interfaces, and overloading.
- Confidence with utility types (Partial/Required/Readonly/Pick/Omit), mapped & conditional types, inference with infer, and deep types.
- Module-level skills: namespaces, ES modules, config (tsconfig paths/baseUrl), and project structure.
Browse the Assignments
- Types, Unions & Safety — annotations, inference, literal/union/intersection, void/never, any vs unknown, exhaustive switches, project bootstrap.
- Arrays, Tuples, Enums & Interfaces — typed arrays/tuples, numeric & string enums, type aliases, interface basics/extension, generics intro & utility result types.
- Functions & OOP — parameters/overloads, classes & inheritance, access modifiers, abstract classes, interfaces & implementations, factories, simple patterns.
- Generics & Utilities — generic functions/classes, constraints, pluck/merge/groupBy, Partial/Required/Readonly/Pick/Omit, deep partial/readonly, debounce/throttle/retry helpers.
- Advanced Types, Modules & Namespaces — assertions, mapped/conditional types with infer, keyof & indexed access, declaration merging, namespaces + modules, config & resolution strategies.
Tips for success
- Turn on strict mode in tsconfig.json (“strict”: true, plus “noImplicitAny”: true, “strictNullChecks”: true).
- Prefer type-safe unions over ad-hoc flags; model states with discriminated unions.
- Reach for unknown instead of any when input is untrusted; narrow before use.
- Use utility types and generics to remove duplication; keep functions pure and reusable.
- Keep module boundaries clean: ES modules for code, namespaces only when you truly need them (e.g., declaration merging or grouping ambient types).
Ready to build real confidence in TypeScript? Pick a set below and start solving!
FAQs
Q1. Which TypeScript version should I use?
Use a current TypeScript 5.x. All assignments compile on modern TS and rely on features like improved type inference, modern utility types, and strict options. This applies broadly across all sets.
Q2. Do I need a build tool?
Not required. Start with tsc --init
to create a tsconfig.json
, compile with tsc
, and run the output with Node. You can add Vite, ts-node, or tsx later if you want faster feedback.
Q3. How do I verify my answers?
First, ensure there are no type errors using tsc --noEmit
. Then run examples to check behavior. For exhaustiveness, let the compiler guide you by using never
in switches and discriminated unions.
Q4. What’s the difference between type aliases and interface?
Both model shapes and can be extended. Interfaces support declaration merging and are great for public object contracts. Type aliases excel at unions, intersections, and complex mapped or conditional types. You’ll practice both styles.
Q5. When should I use unknown vs any?
Use unknown
for untrusted inputs—you must narrow before using it. any
opts out of type-checking and should be used only as a last resort. Several exercises compare the two directly.
Q6. How can I practice generics effectively?
Implement reusable helpers such as pluck
, groupBy
, reverseArray
, Stack<T>
, and Repository<T>
with constraints and inference. Add tests that show type errors for incorrect calls.
Q7. Do we cover mapped and conditional types with infer?
Yes. Expect tasks like DeepPartial
, DeepReadonly
, Flatten
, recreating ReturnType
and PromiseType
, and property pickers using keyof
and indexed access.
Q8. Are modules and namespaces both required?
You’ll practice ES modules with import/export, plus namespaces for advanced or legacy scenarios and declaration merging. Config tasks also include baseUrl
and paths
.
Q9. How should I approach OOP tasks?
Start with simple classes, then add access modifiers, abstract classes, and interfaces. Verify overrides and polymorphism with arrays of base types calling virtual methods.
Q10. How much time should I spend per assignment?
Plan 20–60 minutes per difficulty band (Basic, Intermediate, Advanced). Generics and deep types may take longer initially—aim for correctness and clarity over shortcuts.