JavaScript is the most accessible platform of our times. Yet, it has many downsides, especially in terms of big scale applications, created by multiple developers. TypeScript is the solution. Being the new guy, it has already found its place among rivals such as CoffeeScript and ES6. TypeScript is the Angular2 language. It has bindings for lots of existing libraries. Some people, like me, would choose TypeScript for development of any new project. So why is that? In this talk I'll highlight the native-JS problems that TS solves and compare it to its rivals, CoffeeScript and ES6. I'll mention the similarities between TypeScript and Java. We'll see how do non-Frontenders see TypeScript. I'll share my experience of banking software development.
5. private customer banking interface
TypeScript-based
1+ year to go on production
deployed on 120+ Scandinavian banks
PortalBank
6. massive fake data generator
based on:
JSON Schema
faker.js, chance.js
started in 2014
rewritten to TS in 2016, v0.3
json-schema-faker.js.org
github.com/json-schema-faker/json-schema-faker
13. problems TS solves
1. checks types
test.ts(5,5): error TS2345: Argument of type 'string'
is not assignable to parameter of type 'number'.
14. problems TS solves
3. less unit tests
assert.isString
assert.isNumber
assert.isBoolean
problem exists in all weakly-typed languages
2. less runtime bugs
16. problems TS solves
5. reduces JS pitfalls
// JS
var a = 4;
var b = 5;
var c = a * b;
// c == 20
// JS
var a = "hello";
var b = "world";
var c = a * b;
// c == NaN
// TS
var a: string = "hello";
var b: string = "world";
var c: string = a * b;
// TS
var a = "hello";
var b = "world";
var c = a * b;
test.ts(4,5): error TS2322: Type 'number' is not assignable to
type 'string'.
test.ts(4,17): error TS2362: The lefthand side of an arithmetic
operation must be of type 'any', 'number' or an enum type.
test.ts(4,21): error TS2363: The righthand side of an arithmetic
operation must be of type 'any', 'number' or an enum type.
17. problems TS solves
6. disables JS hacks
var mod = null;
function logic(){...}
module.exports = function(){
mod = mod || require('MODULE');
return logic.apply(...);
}
?
18. problems TS solves
7. native modules
module outer {
var str = "hello world";
module inner {
var num = 6;
}
}
var outer;
(function (outer) {
var str = "hello world";
var inner;
(function (inner) {
var num = 6;
})(inner || (inner = {}));
})(outer || (outer = {}));
19. problems TS solves
8. big business logic
under control
Design
Patterns
Domain
Driven
Design
20. DDD: Value Objects
CORE
M1 M2 M3 extend base
object
var price = 7.99;
var price = {
amount: 7.99,
currency: "PLN"
};
28. problems TS doesn't solve
2. still need to understand JS
writing TS without
knowing JS == disaster
what output will TS
provide?
read code in terms of
both: OOP and async
runtime
29. problems TS doesn't solve
3. won't make it faster
won't make you code faster
won't make app run faster
actually, will slow both down
just a little bit
TS might produce more code
than pure JS (modules, classes)
30. problems TS doesn't solve
4. the any type
stands for NO TYPE
very easy to use
very messy to use
it's very tempting
sometimes just can't do without
will spoil your app if used in big amounts
just like donuts...
40. transpiling JS
pros & cons
more features
might be less code
efficiency
following trends
more code complexity
higher entry-level
for BE & junior devs
IDE support needed
more setup complex
value of the
new features
costs of
introducing it>
?
41. “ think about the problems you
solve, NOT the tools
“ always be responsible for the
tools you introduce
“ nothing comes for free
“ all decisions have pros
and cons