#5181 - Mutable Keys (#5182)

Co-authored-by: Yugang Cao <34439652+Talljack@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2021-12-16 15:42:25 +08:00 committed by GitHub
parent b081a5eb8f
commit daa9bbe94a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,8 @@
Implement the advanced util type MutableKeys<T>, which picks all the mutable (not readonly) keys into a union.
For example:
```ts
type Keys = MutableKeys<{ readonly foo: string; bar: number }>;
// expected to be “bar”
```

View File

@ -0,0 +1,8 @@
difficulty: hard
title: Mutable Keys
tags: utils
related: '2793'
author:
github: Talljack
name: Yugang Cao

View File

@ -0,0 +1 @@
type MutableKeys<T> = any

View File

@ -0,0 +1,8 @@
import { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<MutableKeys<{ a: number, readonly b: string }>, "a">>,
Expect<Equal<MutableKeys<{ a: undefined, readonly b: undefined }>, "a">>,
Expect<Equal<MutableKeys<{ a: undefined, readonly b?: undefined, c: string, d: null }>, "a" | "c" | "d">>,
Expect<Equal<MutableKeys<{}>, never>>
]