5

In React Native Example Code, you'll find at some files the type statement, which encapsulates 4 properties (I'd like to guess), where the last two ones are suffixed with question marks.

type MapRegion = {
  latitude: number,
  longitude: number,
  latitudeDelta?: number,
               ^============   What are these...
  longitudeDelta?: number,
};              ^===========...question marks for? 

What does all this mean? In specification of ECMAScript 6 I can't find anything regarding "type".

Brigand
  • 84,529
  • 20
  • 165
  • 173
delete
  • 18,144
  • 15
  • 48
  • 79

2 Answers2

5

That is flow, a transpiler language that adds static typing to JavaScript.

type MapRegion = {
  latitude: number,
  longitude: number,
  // This property is nullable
  latitudeDelta?: number,
  // This property is nullable
  longitudeDelta?: number,
}; 

// The following does not cause a compilation error

/* @flow */
var a:MapRegion = {
  latitude: 1,
  longitude: 3 
};
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217
5

Facebook is actually using their version of statically typed transpiled JavaScript called 'Flow'. That is what you are seeing here. It is somewhat similar to TypeScript so they can easily be mistaken for each other.

http://flowtype.org/

rmevans9
  • 5,472
  • 1
  • 21
  • 18