Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Hijrah ke TypeScript

Hijrah ke TypeScript

Ariya Hidayat

December 11, 2019
Tweet

More Decks by Ariya Hidayat

Other Decks in Programming

Transcript

  1. > biodata = { nama: 'Budi', umur: 34 } {

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

    nama: 'Budi', umur: 34 } > console.log(biodata.umur) 34
  3. export class LoginForm extends Component { static propTypes = {

    submitAction: PropTypes.func.require, } }
  4. { "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
  5. import React, { Component } from 'react'; Could not find

    a declaration file for module ‘react’
  6. 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": ""
  7. > 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
  8. function todayIsNotWeekend() { const day = moment().utcOffset(7).isoWeekday(); const SATURDAY =

    6; const SUNDAY = 0; return (day !== SATURDAY) || (day !== SUNDAY); }
  9. > 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); ~~~~~~~~~~~~~~
  10. function todayIsNotWeekend() { const day = moment().utcOffset(7).isoWeekday(); const SATURDAY =

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

    6; const SUNDAY = 0; return (day === SATURDAY) || (day === SUNDAY); } export function todayIsNotWeekend() { return !todayIsWeekend(); }
  12. > npm run typecheck src/Inbox.js:12:14 - error TS2365: Operator '>'

    cannot be applied to types 'boolean' and 'number'. 12 (!unreadCount > 0) ? <BellIcon/> : <ClearIcon/> ~~~~~~~~~~~~~~~~
  13. > npm run typecheck src/LoginForm.js:15:29 - error TS2339: Property 'email'

    does not exist on type 'LoginForm'. 15 if (isValidEmail(this.email)) { ~~~~~
  14. validate() { let {email} = this.state; if (isValidEmail(email)) { this.setState({message:

    ''}); } else { this.setState({message: INVALID_EMAIL}); } }
  15. 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",