Slide 1

Slide 1 text

Hijrah ke TypeScript https://unsplash.com/photos/Fq--9iqymkI

Slide 2

Slide 2 text

With great power, comes great responsibility -- Gundala

Slide 3

Slide 3 text

Konon, di jaman purbakala…

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

> biodata = { nama: 'Budi', umur: 34 } { nama: 'Budi', umur: 34 } > console.log(biodata.usia) undefined

Slide 6

Slide 6 text

> biodata = { nama: 'Budi', umur: 34 } { nama: 'Budi', umur: 34 } > console.log(biodata.umur) 34

Slide 7

Slide 7 text

export class LoginForm extends Component { static propTypes = { submitAction: PropTypes.func.require, } }

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Jenazah engineer bikin rusuh karena dulu nggak pakai TypeScript

Slide 13

Slide 13 text

Transisi Gradual

Slide 14

Slide 14 text

{ "compilerOptions": { "target": "esnext", "module": "commonjs", "allowJs": true, "checkJs": true, "noEmit": true, "skipLibCheck": true "noEmitOnError": true, "jsx": "react-native", "moduleResolution": "node", "esModuleInterop": true }, "include": ["**/*.js"], "exclude": ["thirdparty/**.js"] } tsconfig.json

Slide 15

Slide 15 text

> npm install –save typescript

Slide 16

Slide 16 text

import React, { Component } from 'react'; Could not find a declaration file for module ‘react’

Slide 17

Slide 17 text

> npm install –save @types/react > npm install –save @types/react-native

Slide 18

Slide 18 text

Property 'require' does not exist on type 'Requireable<(...args: any[]) => any>’. ts(2339)

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

diff --git a/package.json b/package.json index c9a3d0c..c0dfca4 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "", "main": "src/index.js", "scripts": { + "typecheck": "tsc -p src" }, "author": ""

Slide 21

Slide 21 text

> npm run typecheck src/LoginForm.js:16:38 - error TS2339: Property 'require' does not exist on type 'Requireable<(...args: any[]) => any>’. 16 submitAction: PropTypes.func.require, ~~~~~~~ CI/CD

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

function todayIsNotWeekend() { const day = moment().utcOffset(7).isoWeekday(); const SATURDAY = 6; const SUNDAY = 0; return (day !== SATURDAY) || (day !== SUNDAY); }

Slide 24

Slide 24 text

> npm run typecheck src/Order.js:7:35 - error TS2367: This condition will always return 'true' since the types '6' and '0' have no overlap. 7 return (day !== SATURDAY) || (day !== SUNDAY); ~~~~~~~~~~~~~~

Slide 25

Slide 25 text

function todayIsNotWeekend() { const day = moment().utcOffset(7).isoWeekday(); const SATURDAY = 6; const SUNDAY = 0; return (day !== SATURDAY) && (day !== SUNDAY); }

Slide 26

Slide 26 text

function todayIsWeekend() { const day = moment().utcOffset(7).isoWeekday(); const SATURDAY = 6; const SUNDAY = 0; return (day === SATURDAY) || (day === SUNDAY); } export function todayIsNotWeekend() { return !todayIsWeekend(); }

Slide 27

Slide 27 text

render() { return ( (!unreadCount > 0) ? : ) }

Slide 28

Slide 28 text

> npm run typecheck src/Inbox.js:12:14 - error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'. 12 (!unreadCount > 0) ? : ~~~~~~~~~~~~~~~~

Slide 29

Slide 29 text

!unreadCount > 0 (!unreadCount) > 0 Boolean Number

Slide 30

Slide 30 text

render() { return ( (unreadCount == 0) ? : ) }

Slide 31

Slide 31 text

validate() { let {email} = this.state; if (isValidEmail(this.email)) { this.setState({message: ''}); } else { this.setState({message: INVALID_EMAIL}); } }

Slide 32

Slide 32 text

> npm run typecheck src/LoginForm.js:15:29 - error TS2339: Property 'email' does not exist on type 'LoginForm'. 15 if (isValidEmail(this.email)) { ~~~~~

Slide 33

Slide 33 text

validate() { let {email} = this.state; if (isValidEmail(email)) { this.setState({message: ''}); } else { this.setState({message: INVALID_EMAIL}); } }

Slide 34

Slide 34 text

Musuhnya kebanyakan nih

Slide 35

Slide 35 text

> npm install –save tsc-silent

Slide 36

Slide 36 text

diff --git a/package.json b/package.json index be761d1..58a2aca 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "src/index.js", "scripts": { - "typecheck": "tsc -p src" + "typecheck": "tsc-silent -p src/tsconfig.json --suppressConfig src/tsc-silent.config.js" }, "author": "", "license": "ISC",

Slide 37

Slide 37 text

module.exports = { suppress: [ { pathRegExp: '/.*.js$', codes: [ 2339, 2367 ] } ] } tsc-silent.config.js

Slide 38

Slide 38 text

> npm run typecheck Visible errors: 0, suppressed errors: 2

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Engineering Excellence

Slide 42

Slide 42 text

Rekayasa Paripurna

Slide 43

Slide 43 text

Some artworks are from http://openclipart.org. @ariya114