Skip to content

Instantly share code, notes, and snippets.

@yunghoy
Last active January 12, 2020 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunghoy/71d7768d4170e78a3dff7a09c3a313e5 to your computer and use it in GitHub Desktop.
Save yunghoy/71d7768d4170e78a3dff7a09c3a313e5 to your computer and use it in GitHub Desktop.
Typescript types.
From the codes I wrote 3 years ago. Find code from my cloud storage.
interface KeyValue1 {
[key: string]: string[];
}
const test1: KeyValue1 = {
"key1": ["value1"],
"key2": ["value2"],
};
console.log(JSON.stringify(test1));
interface KeyValue2 {
[key: string]: string;
}
const test2: KeyValue2 = {
"key1": "value1",
"key2": "value2",
};
console.log(JSON.stringify(test2));
interface KeyValue3 { // Actually, key field in the definition of type is not that important.
[a: string]: string;
}
const test3: KeyValue3 = {
"key1": "value1",
"key2": "value2",
};
console.log(JSON.stringify(test3));
interface KeyValue4 {
[key: number]: string;
}
const test4: KeyValue4 = {
1: "value1",
2: "value2",
};
console.log(JSON.stringify(test4));
const test11: KeyValue1[] = [
{
"key1": ["value1"],
"key2": ["value2"],
}, {
"key3": ["value3"],
"key4": ["value4"],
}
];
console.log(JSON.stringify(test11));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment