1

Let's say i have an array of types:

const arr: Foo[]: [
  a: Foo<A>,
  b: Foo<B>,
  c: Foo<C>,
];

How to limit the array to be NOT a type

const arr: Foo<Not<B>>[]: [
  a: Foo<A>,
  b: Foo<B>, // error
  c: Foo<C>,
];
1
  • Can you show how Foo is defined? Commented Jun 10, 2020 at 12:41

1 Answer 1

1

One way of doing that is to use the Exclude utility type to specify a susbet of the type parameters that Foo can accept, something like this

type Foo<T> = {
    value: T
}

type Bar = string | boolean | number
type BarWithoutBoolean = Exclude<Bar, boolean>

const arr: Foo<BarWithoutBoolean>[] = [
    { value: 1     },
    { value: "abc" }, 
    { value: true  } // Err
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.