1

I recently came across this strange JavaScript code:

export type ImageSource = {
  id: string,
  URI: string,
  thumbnail: string,
  title: ?string,
  description: ?string
}

type Props = {
  images: Array<ImageSource>,
  onPressImage?: Function,
  topMargin?: number,
  closeText?: string,
  infoTitleStyles?: Animated.View.style,
  infoDescriptionStyles?: Animated.View.style,
  enableTilt?: boolean
}

If I understand it correctly, string is a data type, but can someone explain, what is the difference between string and ?string.

Also, what does the following line of code mean:

topMargin?: number,

I've got it from a sample react-native app, I'm assuming, it signifies an optional property, but I can't find any explanation when googling for it.

2
  • 1
    It looks like typescript and it means that the field is optional, effectively: number or undefined typescriptlang.org/docs/handbook/… Commented Sep 5, 2018 at 2:28
  • 1
    could be flow too flow.org Commented Sep 5, 2018 at 3:00

1 Answer 1

1

This is most probably either Typescript or Flow. topMargin?: number represents an optional parameter and title: ?string represents maybe types.

Sign up to request clarification or add additional context in comments.

2 Comments

Wondering, if this is a common thing, why it's not being referred to in any of the react-native documentation?
TypeScript is a strongly typed, object oriented, compiled language. Mostly people code in Javascript, and if it was flow; flow is a static typechecker for javascript, sort of like a plugin, so it doesn't make sense to add it to documentation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.