Created basic files; still incomplete

This commit is contained in:
fkereki
2018-03-24 15:52:52 -03:00
parent c989356391
commit 21289fcd9b
7 changed files with 140 additions and 68 deletions
+11
View File
@@ -0,0 +1,11 @@
[ignore]
[include]
[libs]
[lints]
[options]
[strict]
+11
View File
@@ -0,0 +1,11 @@
[ignore]
[include]
[libs]
[lints]
[options]
[strict]
+1 -1
View File
@@ -26,7 +26,7 @@
"node": true
},
"extends": ["eslint:recommended", "plugin:flowtype/recommended"],
"plugins": ["flowtype"],
"plugins": ["babel", "flowtype"],
"rules": {
"no-console": "off"
}
+5 -3
View File
@@ -1,3 +1,5 @@
// @flow
class ExtDate extends Date {
fullDate() {
const months = [
@@ -16,7 +18,7 @@ class ExtDate extends Date {
];
return (
months[this.getMonth()] +
months[this.getMonth()] +
" " +
String(this.getDate()).padStart(2, "0") +
" " +
@@ -41,7 +43,7 @@ class ExtDate extends Date {
];
return months[m];
}
fullDate2() {
return (
ExtDate.getMonthName(this.getMonth()) +
@@ -55,5 +57,5 @@ class ExtDate extends Date {
console.log(new ExtDate().fullDate()); // "MAY 01 2018"
console.log(ExtDate.getMonthName(8)); // "SEP"
console.log(ExtDate.getMonthName(8)); // "SEP"
console.log(new ExtDate().fullDate2()); // "MAY 01 2018"
+60 -64
View File
@@ -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,68 +63,64 @@ const countKeysMixin = base =>
}
};
class PersonWithTwoMixins extends toJsonMixin(countKeysMixin(Person)) {
toJson() {
// redefine the method, just for the sake of it
return "NEW TOJSON " + super.toJson();
}
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
class ExtDate extends Date {
fullDate() {
const months = [
"JAN",
"FEB",
"MAR",
"APR",
"MAY",
"JUN",
"JUL",
"AUG",
"SEP",
"OCT",
"NOV",
"DEC"
];
return (
months[this.getMonth()] +
" " +
String(this.getDate()).padStart(2, "0") +
" " +
this.getFullYear()
);
}
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 {
fullDate() {
const months = [
"JAN",
"FEB",
"MAR",
"APR",
"MAY",
"JUN",
"JUL",
"AUG",
"SEP",
"OCT",
"NOV",
"DEC"
];
return (
months[this.getMonth()] +
" " +
String(this.getDate()).padStart(2, "0") +
" " +
this.getFullYear()
);
}
static getMonthName(m) {
const months = [
"JAN",
"FEB",
// etc...
"NOV",
"DEC"
];
return months[m];
}
fullDate2() {
return (
ExtDate.getMonthName(this.getMonth()) +
" " +
String(this.getDate()).padStart(2, "0") +
" " +
this.getFullYear()
);
}
static getMonthName(m) {
const months = [
"JAN",
"FEB",
// etc...
"NOV",
"DEC"
];
return months[m];
}
console.log(new ExtDate().fullDate()); // "MAY 01 2018"
fullDate2() {
return (
ExtDate.getMonthName(this.getMonth()) +
" " +
String(this.getDate()).padStart(2, "0") +
" " +
this.getFullYear()
);
}
}
console.log(new ExtDate().fullDate()); // "MAY 01 2018"
+19
View File
@@ -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);
+33
View File
@@ -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