Remove the key starting with _
from given type T
.
/* _____________ Your Code Here _____________ */
type PublicType<T extends object> = {
[Key in keyof T as Key extends `_${string}` ? never: Key]: T[Key]
}
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<PublicType<{ a: number }>, { a: number }>>,
Expect<Equal<PublicType<{ _b: string | bigint }>, {}>>,
Expect<Equal<PublicType<{ readonly c?: number }>, { readonly c?: number }>>,
Expect<Equal<PublicType<{ d: string; _e: string }>, { d: string }>>,
Expect<Equal<PublicType<{ _f: () => bigint[] }>, {}>>,
Expect<Equal<PublicType<{ g: '_g' }>, { g: '_g' }>>,
Expect<Equal<PublicType<{ __h: number; i: unknown }>, { i: unknown }>>,
]
- Typescript Challenges Medium Public Typetypescript challenges medium public checkrepeatedtuple typescript challenges medium typescript challenges mergeall medium typescript challenges transpose hard typescript triangular medium number cartesianproduct typescript challenge medium type typescript expression error performance typescript interface type typescript predicates type all typescript interface type