Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flowtype: array of possible strings cannot be empty?

Tags:

flowtype

if I create this Flow type:

export type List = [
    'some' |
    'strings' |
    'allowed' |
    'to' |
    'use'
];

I am not allowed to: const myList: List = [];

this is the error: empty array literal: This type is incompatible with a tuple type that expects a 1st element of non-optional type string enum

The only thing I can come up with is adding typeof undefined to the possible values list. But there must be a simpeler way to allow it to be empty?

like image 363
Laurens Kling Avatar asked Dec 23 '22 23:12

Laurens Kling


1 Answers

You defined a tuple of one element, you may want

type Element = 
  'some' |
  'strings' |
  'allowed' |
  'to' |
  'use';

export type List = Element[];
// or export type List = Array<Element>;

const myList: List = []
like image 137
gcanti Avatar answered Jan 15 '23 10:01

gcanti