这是indexloc提供的服务,不要输入任何密码
Skip to content

2793 - Mutable (🎥 Video Explanation and Solution) #23743

@dimitropoulos

Description

@dimitropoulos

2793 - Mutable

Mutable takes in an object with readonly properties and makes them all mutable. "Take THAT functional programmers!"

🎥 Video Explanation

Release Date: 2023-02-22 19:00 UTC

Mutable

🔢 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions