mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-01 21:32:35 +02:00
Fix recursive types example in typescript roadmap (#4022)
Co-authored-by: Itamar Zwi <itamarz@amplicy.io>
This commit is contained in:
@@ -5,7 +5,10 @@ Recursive types in TypeScript are a way to define a type that references itself.
|
|||||||
For example, the following is a recursive type that represents a linked list:
|
For example, the following is a recursive type that represents a linked list:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
type LinkedList<T> = T & { next: LinkedList<T> };
|
type LinkedList<T> = {
|
||||||
|
value: T;
|
||||||
|
next: LinkedList<T> | null;
|
||||||
|
};
|
||||||
|
|
||||||
let list: LinkedList<number> = {
|
let list: LinkedList<number> = {
|
||||||
value: 1,
|
value: 1,
|
||||||
|
Reference in New Issue
Block a user