0

I'm in the middle of a typescript course. We're learning generics and the following example is shown

const hobbies: Array<string> = ['coding', 'eating']

Now before I learned to check an array of type using the following syntax

const hobbies: string[] = ['coding', 'eating']

Can anyone explain me what the difference is?

0

1 Answer 1

2

Those two mean the same thing. So i can see that as a useful example for introducing the concept of generics, since it takes a concept you're already familiar with (arrays) and shows another way it can be done. But generics can also be used in a broader range of contexts than just arrays.

Sign up to request clarification or add additional context in comments.

2 Comments

What's the preferred method you think?
The way I handle it: simple types with string[], more complicated types (e.g. union types, in-line object types) w/ Array<string l number> since it’s more readable in my opinion.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.