Created basic files; still incomplete
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
[ignore]
|
||||
|
||||
[include]
|
||||
|
||||
[libs]
|
||||
|
||||
[lints]
|
||||
|
||||
[options]
|
||||
|
||||
[strict]
|
||||
@@ -0,0 +1,11 @@
|
||||
[ignore]
|
||||
|
||||
[include]
|
||||
|
||||
[libs]
|
||||
|
||||
[lints]
|
||||
|
||||
[options]
|
||||
|
||||
[strict]
|
||||
@@ -26,7 +26,7 @@
|
||||
"node": true
|
||||
},
|
||||
"extends": ["eslint:recommended", "plugin:flowtype/recommended"],
|
||||
"plugins": ["flowtype"],
|
||||
"plugins": ["babel", "flowtype"],
|
||||
"rules": {
|
||||
"no-console": "off"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// @flow
|
||||
|
||||
class ExtDate extends Date {
|
||||
fullDate() {
|
||||
const months = [
|
||||
|
||||
+11
-15
@@ -24,7 +24,7 @@ class Person {
|
||||
}
|
||||
}
|
||||
|
||||
pp = new Person("Erika", "Mustermann");
|
||||
let pp = new Person("Erika", "Mustermann");
|
||||
console.log(pp); // Person {first: "Erika", last: "Mustermann"}
|
||||
console.log(pp.initials()); // "EM"
|
||||
console.log(pp.fullName()); // "Erika Mustermann"
|
||||
@@ -44,7 +44,7 @@ class Developer extends Person {
|
||||
}
|
||||
}
|
||||
|
||||
window.dd = new Developer("John", "Doe", "JS");
|
||||
let dd = new Developer("John", "Doe", "JS");
|
||||
console.log(dd); // Developer {first: "John", last: "Doe", language: "JS"}
|
||||
console.log(dd.initials()); // "JD"
|
||||
console.log(dd.fullName()); // "John Doe, JS dev"
|
||||
@@ -63,22 +63,19 @@ const countKeysMixin = base =>
|
||||
}
|
||||
};
|
||||
|
||||
class PersonWithTwoMixins extends toJsonMixin(countKeysMixin(Person)) {
|
||||
class PersonWithTwoMixins extends toJsonMixin(countKeysMixin(Person)) {
|
||||
toJson() {
|
||||
// redefine the method, just for the sake of it
|
||||
return "NEW TOJSON " + super.toJson();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let p2m = new PersonWithTwoMixins("Jane", "Roe");
|
||||
console.log(p2m);
|
||||
console.log(p2m.toJson()); // NEW TOJSON {"first":"Jane","last":"Roe"}
|
||||
console.log(p2m.countKeys()); // 2
|
||||
|
||||
p2m = new PersonWithTwoMixins("Jane", "Roe");
|
||||
console.log(p2m);
|
||||
console.log(p2m.toJson()); // NEW TOJSON {"first":"Jane","last":"Roe"}
|
||||
console.log(p2m.countKeys()); // 2
|
||||
|
||||
|
||||
|
||||
class ExtDate extends Date {
|
||||
class ExtDate extends Date {
|
||||
fullDate() {
|
||||
const months = [
|
||||
"JAN",
|
||||
@@ -104,7 +101,6 @@ const countKeysMixin = base =>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
static getMonthName(m) {
|
||||
const months = [
|
||||
"JAN",
|
||||
@@ -125,6 +121,6 @@ const countKeysMixin = base =>
|
||||
this.getFullYear()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(new ExtDate().fullDate()); // "MAY 01 2018"
|
||||
console.log(new ExtDate().fullDate()); // "MAY 01 2018"
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/* @flow */
|
||||
/* eslint-disable no-unused-vars */
|
||||
|
||||
let flag: number | boolean;
|
||||
flag = true; // OK
|
||||
flag = 1; // also OK
|
||||
flag = "1"; // error: wrong type
|
||||
|
||||
let traffic: "red" | "amber" | "green"; // traffic is implicitly string
|
||||
traffic = "yellow"; // error: not allowed
|
||||
|
||||
type numberOrString = number | string;
|
||||
|
||||
function addTwo(x: numberOrString, y: numberOrString) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
const fs: any = require("fs");
|
||||
fs.readFile("/somefilename.ext", processData);
|
||||
@@ -0,0 +1,33 @@
|
||||
/* @flow */
|
||||
/* eslint-disable no-unused-vars */
|
||||
|
||||
let someFlag: boolean;
|
||||
let greatTotal: number;
|
||||
let firstName: string;
|
||||
|
||||
function toString(x: number): string {
|
||||
return String(x);
|
||||
}
|
||||
|
||||
function addTwo(x: number | string, y: number | string) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
function showValue(z: mixed): void {
|
||||
// not returning anything
|
||||
console.log("Showing... ", z);
|
||||
}
|
||||
|
||||
let numbersList: Array<number>;
|
||||
numbersList = [22, 9, 60]; // OK
|
||||
numbersList[1] = "SEP"; // error; cannot assign a string to a number
|
||||
|
||||
let anotherList: number[];
|
||||
|
||||
let sealedObject: { name: string, age?: number };
|
||||
sealedObject.name = "Ivan Horvat"; // OK
|
||||
sealedObject.id = 229; // error: key isn't defined in the data type
|
||||
sealedObject = { age: 57 }; // error: mandatory field is missing
|
||||
|
||||
let unsealedObject = {};
|
||||
unsealedObject.id = 229; // OK
|
||||
Reference in New Issue
Block a user