Types and .flowconfig changes

This commit is contained in:
fkereki 2018-03-27 13:41:03 -03:00
parent a93509f7f9
commit 3b8015cc52
4 changed files with 44 additions and 1 deletions

View File

@ -5,7 +5,10 @@
[libs]
[lints]
all=warn
unsafe-getters-setters=off
[options]
include_warnings=true
[strict]

View File

@ -0,0 +1,14 @@
/* @flow */
import {
milesToKm,
ouncesToGrams,
poundsToKg as p_to_kg
} from "./module_conversions.js";
console.log(`A miss is as good as ${milesToKm(1)} kilometers.`);
console.log(
`${ouncesToGrams(1)} grams of protection `,
`are worth ${p_to_kg(1) * 1000} grams of cure.`
);

View File

@ -0,0 +1,26 @@
/* @flow */
type conversion = number => number;
const SPEED_OF_LIGHT_IN_VACUUM_IN_MPS = 186282;
const KILOMETERS_PER_MILE = 1.60934;
const GRAMS_PER_POUND = 453.592;
const GRAMS_PER_OUNCE = 28.3495;
const milesToKm: conversion = m => m / KILOMETERS_PER_MILE;
const kmToMiles: conversion = k => k * KILOMETERS_PER_MILE;
const poundsToKg: conversion = p => p / (GRAMS_PER_POUND / 1000);
const kgToPounds: conversion = k => k * GRAMS_PER_POUND / 1000;
const gramsToOunces: conversion = g => g / GRAMS_PER_OUNCE;
const ouncesToGrams: conversion = o => o * GRAMS_PER_OUNCE;
/*
It's usually preferred to include all "export"
statements together, at the end of the file.
You need not have a SINGLE export, however.
*/
export { milesToKm, kmToMiles };
export { poundsToKg, kgToPounds, gramsToOunces, ouncesToGrams };
export { SPEED_OF_LIGHT_IN_VACUUM_IN_MPS };

View File

@ -20,7 +20,7 @@ class Person {
first: string;
last: string;
constructor(first, last) {
constructor(first: string, last: string) {
this.first = first;
this.last = last;
}