arktypea
arktype16mo ago
Dimava

Generic with Narrow/Morph

I want to make something like
type UniqueArray<T, K extends keyof T>


export const UniqueArray = brandsScope.type.generic('T', 'K extends keyof T', ['T[]', ':', (v, ctx) => {
  let vals = new Set(v.map(e => e[erm what]))
  if (vals.length !== v.length) return ctx.mustBe(`array with uniue $K`)
  return true
}])

Please help me to make it work
Was this page helpful?