Skip to content

Commit 6ea3fd5

Browse files
committed
add keyof
1 parent 2f68e8a commit 6ea3fd5

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tests/test_ts_utility.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ class TodoTD(TypedDict):
5959
]
6060
]
6161

62+
# KeyOf[T]
63+
# Constructs a union of the names of every member of T.
64+
type KeyOf[T] = Union[
65+
*[p.name for p in typing.Iter[typing.Members[T]]]
66+
]
67+
6268
# Exclude<T, U>
6369
# Constructs a type by excluding from T all union members assignable to U.
6470
type Exclude[T, U] = Union[
@@ -203,3 +209,9 @@ def test_extract():
203209
)
204210

205211
assert eval_typing(Extract[str | int | float, str | int]) == (str | int)
212+
213+
214+
def test_keyof():
215+
assert eval_typing(KeyOf[Todo]) == (
216+
Literal["title"] | Literal["description"] | Literal["completed"]
217+
)

0 commit comments

Comments
 (0)