1

I was looking at a repo on Github when I stumbled on this file : https://github.com/cdebotton/react-universal/blob/master/app/entryPoints/client.js And more precisely the line 13:

let createDevToolsWindow: ?Function;

And I have no idea what this "[...]? :Function;" syntax is. I looked in the commits which introduced it, I searched in ES2015+, tried to find it on Google but I don't know how it's called so I didn't find anything.

Is this some Node thing? Or am I just really bad at JS?...

0

1 Answer 1

1

This code is using flow and the prefixed ? means that null is allowed. More examples:

var array_of_num: number[] = [];
var array_of_num_alt: Array<number> = [];
var optional_array_of_num: ?number[] = null;
var array_of_optional_num: Array<?number> = [null, 0];

Another example:

// okay, 1 is a number
var good: number = 1;  

// okay, we have a ?
var good_nullable: ?number = null; 

// not okay, no ? means null is not a valid value for this variable.    
var bad: number = null;
Sign up to request clarification or add additional context in comments.

2 Comments

So if I understand correctly, it's used to specify the type of the variable, like you would do in C, for example? "int num = 0;" But with a '?' you specify the var can also be 'null'.
Right, I recommend spending a few minutes with the getting started tutorial: flowtype.org/docs/getting-started.html I'll add another example too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.