Hyperlinkv0.8.0-beta.28

SchemaAST

SchemaAST.IndexSignatureclasseffect/SchemaAST.ts:1971
IndexSignature

Represents an index signature entry within an Objects node.

When to use

Use when constructing or inspecting object AST entries for record-like keys and values.

Details

  • parameter — the key type AST (e.g. String for string keys, TemplateLiteral for patterned keys).
  • type — the value type SchemaAST.
  • merge — optional KeyValueCombiner for handling duplicate keys.

Gotchas

Using Schema.optionalKey on the value type is not allowed for index signatures (throws at construction); use Schema.optional instead.

export class IndexSignature {
  readonly parameter: IndexSignatureParameter
  readonly type: AST
  readonly merge: KeyValueCombiner | undefined

  constructor(
    parameter: AST,
    type: AST,
    merge: KeyValueCombiner | undefined
  ) {
    if (!isIndexSignatureParameter(parameter)) {
      throw new Error(`Invalid index signature parameter ${parameter._tag}`)
    }
    this.parameter = parameter
    this.type = type
    this.merge = merge
    if (isOptional(type) && !containsUndefined(type)) {
      throw new Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")
    }
  }
}
Referenced by 1 symbols