#Is there a utility type that I can use that is the opposite of `Readonly<T>`?

6 messages · Page 1 of 1 (latest)

glossy sonnet
#

I found this on StackOverflow but I don't understand how it has more than one generic type parameter.

type Writeable<T extends { [x: string]: any }, K extends string> = {
    [P in K]: T[P];
}

Readonly only has one generic type parameter, so I want the same thing for Writable.
I figured TypeScript would have something built-in?

inland ridge
#

That doesn't look like the opposite of Readonly<T>, it looks more like Pick<T, K>.

#
type Mutable<T> = {
    -readonly [K in keyof T]: T[K]
}

type Obj = {
    foo: string
    bar: number
    baz: boolean
}

type ReadonlyObj = Readonly<Obj>
type Roundtrip = Mutable<ReadonlyObj>
#

!ts ReadonlyObj Roundtrip

somber slateBOT
#
type ReadonlyObj = {
    readonly foo: string;
    readonly bar: number;
    readonly baz: boolean;
} /* 11:6, 12:26 */``````ts
type Roundtrip = {
    foo: string;
    bar: number;
    baz: boolean;
} /* 12:6 */```
glossy sonnet
#

ah fantastic, thank you!