userMod2
userMod2

Reputation: 8960

Typescript - Object with any number of key values

I'm trying writing an interface to figure to handle data like this:

interface SessionList {
   appInfo: Object(string: string | null);
}

There could be 0 to many items under appInfo. I'm trying to find the correct syntax but not luck - currently at:

appInfo: Object(string: string | null);

Any ideas?

Upvotes: 5

Views: 2026

Answers (1)

Roberto Zvjerković
Roberto Zvjerković

Reputation: 10127

Either

interface AppInfo {
  [key: string]: string | null;
}

Or

Record<string, string | null>

Update:

let obj: { appInfo: Record<string, string | null> };

interface SessionList {
   appInfo: Record<string, string | null>;
}

let obj: SessionList;

Upvotes: 10

Related Questions