I want to convert this PHP script to TypeScript (nodejs).
$fruits = [
'APPLE'=> [
'color'=>'red',
'size'=>'small'
],
'BANANA'=>[
'color'=>'yellow',
'size'=>'middle'
]
];
echo $fruits['APPLE']['color'];
type info = {
color: string,
size: string
}
const fruits['APPLE']: info = {color:'red',size:'small'}
I get an error.
2
Answers
In TypeScript, you can define an object with a similar structure to your PHP array.
type
for clarity and readability.