mirror of
https://github.com/type-challenges/type-challenges.git
synced 2026-01-25 14:47:17 +00:00
Co-authored-by: Yugang Cao <34439652+Talljack@users.noreply.github.com>
This commit is contained in:
parent
b081a5eb8f
commit
daa9bbe94a
8
questions/5181-hard-mutable-keys/README.md
Normal file
8
questions/5181-hard-mutable-keys/README.md
Normal 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”
|
||||
```
|
||||
8
questions/5181-hard-mutable-keys/info.yml
Normal file
8
questions/5181-hard-mutable-keys/info.yml
Normal file
@ -0,0 +1,8 @@
|
||||
difficulty: hard
|
||||
title: Mutable Keys
|
||||
tags: utils
|
||||
related: '2793'
|
||||
author:
|
||||
github: Talljack
|
||||
name: Yugang Cao
|
||||
|
||||
1
questions/5181-hard-mutable-keys/template.ts
Normal file
1
questions/5181-hard-mutable-keys/template.ts
Normal file
@ -0,0 +1 @@
|
||||
type MutableKeys<T> = any
|
||||
8
questions/5181-hard-mutable-keys/test-cases.ts
Normal file
8
questions/5181-hard-mutable-keys/test-cases.ts
Normal 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>>
|
||||
]
|
||||
Loading…
x
Reference in New Issue
Block a user