Last active
January 12, 2020 15:11
-
-
Save yunghoy/71d7768d4170e78a3dff7a09c3a313e5 to your computer and use it in GitHub Desktop.
Typescript types.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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