Volkan Gul
San Francisco Software engineer at
@ugurvolkangul
Github
@birkasecorba
Volkan Gul San Francisco Software engineer at Github Linkedin - - PowerPoint PPT Presentation
Volkan Gul San Francisco Software engineer at Github Linkedin @birkasecorba @ugurvolkangul We believe in a safe and accessible economy, strengthened by institutional investment. Were working to advance participation in the digital
San Francisco Software engineer at
@ugurvolkangul
Github
@birkasecorba
https://anchorage.com/careers/ We believe in a safe and accessible economy, strengthened by institutional investment. We’re working to advance participation in the digital asset class.
➔ What is the problem?
Current status of JS and Some common issues in Javascript in real world.
➔ How can we solve it?
What type of solutions do we have to fix these issues
➔ Examples & Features
Example solutions to our initial problems
T h e P r
l e m *but, honestly, it is not the best
typeof x // number // string // function // undefined // boolean // symbol // object
Quote
At the source of every error which is blamed on the computer you will find at least two human errors, including the error of blaming it on the computer.
T h e P r
l e m
const x = 10; const y = x.parent; // Where error really happens return y.name; // Where error is reported
T h e P r
l e m
function isItTooMuch(m) { if (m.count > 2) { return 'yes'; } else { return 'no'; } } isItTooMuch(5) // => ?
Quote
Only half of programming is coding. The other 90% is debugging.
function fiveDividedBy(number) { return 5 / num; } fiveDividedBy(5) // => ?
T h e S
u t i
s
function fiveDividedBy(number) { return 5 / num; } fiveDividedBy(5) // => ?
Added bonuses
T h e S
u t i
s
/** * @param greeting: greeting prompt * @param toWhom: list of people to greet * @param howManyTimes: how many times should function greet */ function greet(greeting, toWhom, howManyTimes){ … } // Correct usage greet('hello there', ['General Grievous'], 1); // Incorrect usages greet(); greet('hi', 'Master Kenobi');
T h e S
u t i
s
function greet(greeting, toWhom, howManyTimes) { } if (typeof greeting !== 'string') { throw new Error('first argument must be a string') } if (!Array.isArray(toWhom)) { throw new Error('second argument must be an array') } if (typeof howManyTimes !== 'number') { throw new Error('third argument must be a number') } if (arguments.length !== 3) { throw new Error('must be called with 3 arguments') }
Tests
Solutions like custom type checking should be paired with extensive test coverage to be really effective. The question you should be asking is “can somebody (or me in the future) change and break my code without realizing they broke the logic?”
T h e S
u t i
s
import PropTypes from 'prop-types'; class Greeting extends React.Component { render() { return ( <h1>Hello, {this.props.name}</h1> ); } } Greeting.propTypes = { name: PropTypes.string };
T h e S
u t i
s
It is a strict syntactical superset of JavaScript, and adds
T h e S
u t i
s
E x a m p l e s
E x a m p l e s
E x a m p l e s
the function
E x a m p l e s
E x a m p l e s
E x a m p l e s
E x a m p l e s
and optimize our code with almost no overhead.
Type Systems Will Make You a Better JavaScript Developer - React Conf 2017 Jared Forsyth
https://www.youtube.com/watch?v=V1po0BT7kac
Typescript Docs
https://www.typescriptlang.org/
Why I Was Wrong About TypeScript - GOTO 2018 TJ VanToll
https://www.youtube.com/watch?v=AQOEZVG2WY0
Create React App Docs
https://create-react-app.dev/docs/adding-typescript/