Types and .flowconfig changes
This commit is contained in:
parent
a93509f7f9
commit
3b8015cc52
@ -5,7 +5,10 @@
|
||||
[libs]
|
||||
|
||||
[lints]
|
||||
all=warn
|
||||
unsafe-getters-setters=off
|
||||
|
||||
[options]
|
||||
include_warnings=true
|
||||
|
||||
[strict]
|
||||
|
||||
14
chapter02/src/module_conversion_usage.js
Normal file
14
chapter02/src/module_conversion_usage.js
Normal 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.`
|
||||
);
|
||||
26
chapter02/src/module_conversions.js
Normal file
26
chapter02/src/module_conversions.js
Normal 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 };
|
||||
@ -20,7 +20,7 @@ class Person {
|
||||
first: string;
|
||||
last: string;
|
||||
|
||||
constructor(first, last) {
|
||||
constructor(first: string, last: string) {
|
||||
this.first = first;
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user