How to type object with unknown properties?

In typescript:

interface SomeObj {
  [key: string]: boolean

How to type it with Reason/Rescript?

JavaScript objects are dynamic and troublesome enough that it’s hard to start from the shape and find a general way of binding to it. It’s much more effective to start from the use-case and bind to those bottom-up style. If you can provide a snippet of how you’d want to use that object, I can provide the bindings here.

For example I have ts code as below:

// typings
export interface Resource {
  [language: string]: ResourceLanguage;

export interface ResourceLanguage {
  [namespace: string]: ResourceKey;

// ts code
import i18next from "i18next";
import { langA, langB, langAResources, langBResources } from "./resources";

let options: { resources: Resource } = {
  resources: {
    [langA]: langAResources,
    [langB]: langBResources,


langA/langB are just string variables, they may be changed later, not sure how to make bindings for the init options.

Hey @alcheung.

If you might or might not add keys to an object and you don’t know the length upfront, you’re looking at a dictionary. TypeScript’s {[language: string]: ResourceLanguage} is also the ReScript equivalent of the “dictionary” pattern.

You can look at this sample code, for an example. I put the corresponding TypeScript in comments for comparison.

1 Like

Thx @Maxim! That’s exactly what I’m look for.

you can also use a Map or a Set