https://twitter.com/ryanflorence/status/1751996988525064343
How/Why did TypeScript beat Flow?
I never tried flow and was kinda bullied into TS late, so I wasn’t around to experience how it happened.
9:23 PM · Jan 29, 2024
https://twitter.com/ryanflorence/status/1751996988525064343
How/Why did TypeScript beat Flow?
I never tried flow and was kinda bullied into TS late, so I wasn’t around to experience how it happened.
9:23 PM · Jan 29, 2024
| ### standard commit message | |
| Am using commitzen for the git commit message | |
| It is a one liner eg: `<type>(<scope>): <subject> :gitemoji:` | |
| `type` can be chore, feat or docs | |
| `scope` can be `html`, `css`, `js` or `lint` | |
| and `scope` is optional | |
| `gitemoji` maybe |
| // @flow | |
| // https://flow.org/en/docs/types/unions/#toc-disjoint-unions | |
| type Response = { | |
| success: boolean, | |
| value?: boolean, | |
| error?: string | |
| }; | |
| // works. |
| // @flow | |
| // https://flow.org/en/docs/types/unions/#toc-unions-refinements | |
| // flow can refine on the union. | |
| // and knows when the code is operating on a number here for eg. | |
| // works | |
| function toStringPrimitivesGood(value: number | boolean | string): string { // Error! | |
| if (typeof value === 'number') { | |
| return value.toLocaleString([], { maximumSignificantDigits: 3 }); // Works! |
| // chaining then. chain is then -> catch -> then | |
| // case 1: promise is resolved | |
| new Promise((resolve, reject) => resolve("some data")).then(data => { alert(`data: ${data}`); return data; }).catch(err => { alert(`err: ${err}`); return Promise.reject(err); }).then(data => { alert(`data again: ${data}`); return data; }) | |
| // case 2: promise is rejected | |
| new Promise((resolve, reject) => resolve("some data")).then(data => { alert(`data: ${data}`); return data; }).catch(err => { alert(`err: ${err}`); return Promise.reject(err); }).then(data => { alert(`data again: ${data}`); return data; }) |
| fn main() { | |
| let mut s = String::from("hello world"); | |
| let len = first_word(&s); | |
| { | |
| let word = &s[0..len]; | |
| println!("word is {}", word); // word is hello | |
| } | |
| s.clear(); | |
| let word = &s[0..len]; // thread 'main' panicked at 'byte index 5 is out of bounds of ``', src/libcore/str/mod.rs:2144 | |
| println!("word is {}", word); |
| { | |
| "env": { | |
| "node": true, | |
| "commonjs": true, | |
| "es6": true | |
| }, | |
| "extends": "eslint:recommended", | |
| "rules": { | |
| "accessor-pairs": "error", | |
| "array-bracket-spacing": [ |
| let MODIFY = "MODIFY"; | |
| let ADD = "ADD"; | |
| let DELETE = "DELETE"; | |
| function checkAction(actions, recon, action, cb) { | |
| if (actions.indexOf(action) > -1) { | |
| cb(recon); | |
| } | |
| } |
| const params = { | |
| pagination: { | |
| prevId:1, | |
| nextId: 3 | |
| }, | |
| location: { | |
| query: { | |
| step: 10 | |
| } | |
| } |