TypeScript types to restrict array values

0 votes
Can I use TypeScript types to restrict array inputs to certain elements?

For example, if I wanted to create a type that is an array that could hold any number of elements, but the elements are restricted to the values: "dog", 3, and true, could I do this without allowing any other string, number, or boolean values?
Jul 18, 2022 in TypeSript by Logan
• 2,140 points
952 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In TypeSript

0 votes
1 answer

Is it possible to extend types in Typescript?

you can intersect types: type TypeA = { ...READ MORE

answered Jun 7, 2022 in TypeSript by Nina
• 3,060 points
591 views
0 votes
1 answer

Now I know what 'pick' does. But I want to do the opposite and remove values from an object.

You can use the keyword Omit for ...READ MORE

answered May 27, 2022 in TypeSript by Nina
• 3,060 points
624 views
0 votes
1 answer

Cast a JSON Object to a TypeScript class

I had the same issue and this ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
3,074 views
0 votes
1 answer

How to create ES6 Map in Typescript

Refer this as an example this.configs = new ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
837 views
0 votes
1 answer

How to declare and initialize a Dictionary in Typescript

Apparently this doesn't work when passing the ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
6,496 views
0 votes
1 answer

What is "not assignable to parameter of type never" error in TypeScript?

All you have to do is define ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
57,259 views
0 votes
1 answer

TypeScript: Class Constructor type

class Zoo<T extends Animal> { ...READ MORE

answered Jun 8, 2022 in TypeSript by Nina
• 3,060 points
3,112 views
0 votes
0 answers
0 votes
0 answers

In typescript, why do the | and & operators flip their meaning when used on function types?

In this code, example1 and example2 are confusing me: type F1 = ...READ MORE

Jul 13, 2022 in TypeSript by Logan
• 2,140 points
530 views
0 votes
0 answers

Can PHP arrays hold items of different type?

The definition of an array in other ...READ MORE

Nov 16, 2022 in Database by Ashwini
• 5,430 points
811 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP