Skip to content

Commit a9eaa4b

Browse files
committed
fix: remove optional status from KeysByType keys
Because status modifiers are attached to keys, `KeysByType` gives back an `undefined` key when the original object contains optional keys; even if the optional key is not of the given type. This change fixes that by removing the optional status modifier from the object while iterating over the keys. The downside to this change is that it does not perfectly purify the object. So if other status modifiers are added in the future, we will not necessarily be robust to that change. A more "pure" fix (pun intended) would be to work with a purified object. The downside is that the only way I could figure out to do that would require much uglier code and/or a helper function that would need to be exported. In favor of minimizing "private" exports, I opted for the simple solution. Also a downside here is that we cannot filter by `undefined` if a key is optional. This was already an issue before this commit, so I'm punting on it for now because the fix seems non-trivial. Closes #106
1 parent 92a9ca8 commit a9eaa4b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/types/objects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export type DeepReadonly<T> = Readonly<{
219219
* @returns keys of `O` whose right-side value is `T`
220220
*/
221221
export type KeysByType<O extends object, T> = {
222-
[k in keyof O]: O[k] extends T ? k : never;
222+
[k in keyof O]-?: O[k] extends T ? k : never;
223223
}[keyof O];
224224

225225

0 commit comments

Comments
 (0)