#Help understanding the code

11 messages · Page 1 of 1 (latest)

plush wing
#

I am looking at someone else's code implementation


export interface VocabType {
    code: string;
    recordsHeld: number;
    label: string;
}```

I am trying to understand why they exported interface as a type and what is the line `export type APIResponse= VocabType[];` actually accomplishes?
harsh gull
#

im guessing so when you see

const response: APIResponse = [...]

you know it's the right type but can highlight it and see the detailed fields if you need to

plush wing
#

but that line export type APIResponse= VocabType[]; actually treats VocabType as if it was a variable. Thiat is where my confusion is

harsh gull
#

it doesnt treat it as a variable

#

VocabType is a word that means ```ts
{
code: string;
recordsHeld: number;
label: string;
}

`APIResponse` is a word that means a list of `VocabType`s, more like a synonym than anything
#

its just binding words (symbols) to meanings (types) to help people understand what theyre supposed to represent

plush wing
#

That makes sense

#

another question would it be same if i say export interface APIResponse= VocabType[];

#

as they are aliases

harsh gull
#

unfortunately the typescript syntax doesnt let you

#

to make a synonym you have to use type