Skip to content

string index signature limitation #12

@danielnixon

Description

@danielnixon

Given some type with non-optional properties:

export interface Address {
  street_address: string;
  city: string;
  state: string;
}

we get the following io-ts codec:

const Address = t.type({street_address: t.string, city: t.string, state: t.string})

So good so far. However, if we add a string index signature:

export interface Address {
  street_address: string;
  city: string;
  state: string;
  [k: string]: any;
}

We now get the following io-ts codec:

const Address = t.record(t.string, t.unknown)

That suits the string index signature, but we've lost validation of the three required fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions