-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Open
Description
2793 - Mutable
Mutable takes in an object with readonly properties and makes them all mutable. "Take THAT functional programmers!"
🎥 Video Explanation
🔢 Code
// ============= Test Cases =============
import type { Equal, Expect } from './test-utils'
interface Todo {
title: string
description: string
completed: boolean
meta: {
author: string
}
}
type A1 = Mutable<Readonly<Todo>>;
type B1 = Todo;
type C1 = Expect<Equal<A1, B1>>;
type List = [1, 2, 3]
type A2 = Mutable<Readonly<List>>;
type B2 = List;
type C2 = Expect<Equal<A2, B2>>;
// @ts-expect-error(2344)
type E1 = Mutable<'string'>;
// @ts-expect-error(2344)
type E2 = Mutable<0>;
// ============= Your Code Here =============
type Mutable<T extends Record<string, any>> = {
-readonly [P in keyof T]: T[P]
};➕ More Solutions
For more video solutions to other challenges: see the umbrella list! #21338
Metadata
Metadata
Assignees
Labels
No labels