Hyperlinkv0.8.0-beta.28

Struct

Struct.keysconsteffect/Struct.ts:168
<S extends object>(self: S): Array<keyof S & string>

Returns the string keys of a struct as a properly typed Array<keyof S & string>.

When to use

Use when you want a typed replacement for Object.keys that narrows the result to the known string keys of the struct.

Gotchas

Symbol keys are excluded; only string keys are returned.

Example (Reading typed keys)

import { Struct } from "effect"

const user = { name: "Alice", age: 30, [Symbol.for("id")]: 1 }

const k: Array<"name" | "age"> = Struct.keys(user)
console.log(k) // ["name", "age"]
Key utilitiesgetpick
Source effect/Struct.ts:1682 lines
export const keys = <S extends object>(self: S): Array<(keyof S) & string> =>
  Object.keys(self) as Array<(keyof S) & string>