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 in TypeSript by Logan
• 2,140 points
9 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 in TypeSript by Nina
• 3,020 points
28 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 in TypeSript by Nina
• 3,020 points
20 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 in TypeSript by Nina
• 3,020 points
92 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 in TypeSript by Nina
• 3,020 points
24 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 in TypeSript by Nina
• 3,020 points
219 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 in TypeSript by Nina
• 3,020 points
839 views
0 votes
1 answer

TypeScript: Class Constructor type

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

answered Jun 8 in TypeSript by Nina
• 3,020 points
56 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 in TypeSript by Logan
• 2,140 points
25 views
0 votes
2 answers

How an object array can be converted to string array in java?

System.arraycopy is the most efficient way, but ...READ MORE

answered Aug 8, 2018 in Java by Sushmita
• 6,900 points
2,989 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP