Last active
December 8, 2023 07:43
-
-
Save Tsugami/7a6f7f67b1f03aeeb84a4fbf0b112a7c to your computer and use it in GitHub Desktop.
Type to remove methods from interface in Typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Base { | |
a: unknown; | |
b: unknown; | |
c: unknown; | |
foo(): unknown; | |
bar(): unknown; | |
} | |
type RemoveMethods<T> = { [P in keyof T as T[P] extends (...args: any) => any ? never : P]: T[P] } | |
interface A extends RemoveMethods<Base> { | |
thing: unknown; | |
} | |
declare const foo: A; | |
foo.a // good | |
foo.foo(); // bad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment