TypeScript - Offirmo-team/wiki GitHub Wiki
Une surcouche de typage pour javascript. Voir aussi flow.
https://www.typescriptlang.org/
- ++ https://typescript-exercises.github.io/
- https://github.com/alexreardon/sink/blob/master/docs/learning-typescript.md
- ++ TypeScript Progression Ladder https://dev.to/remojansen/typescript-progression-ladder-3106 (dead http://www.techladder.io/?tech=typescript)
- https://github.com/rmolinamir/typescript-cheatsheet
- https://toddmotto.com/typescript-the-missing-introduction
- https://github.com/Microsoft/TypeScript/wiki/Roadmap
- release notes https://www.typescriptlang.org/docs/tutorial.html#toc-whats-new
- https://www.typescriptlang.org/docs/tutorial.html
News
- 2024 https://bloomberg.github.io/ts-blank-space/
- blog https://devblogs.microsoft.com/typescript/
- +++ https://blog.mariusschulz.com/2017/12/01/typescript-2-4-weak-type-detection
Advocacy
- 2021 ++ https://www.artima.com/weblogs/viewpost.jsp?thread=4639 Are Dynamic Languages Going to Replace Static Languages?
- 2021 ++ https://developer.chrome.com/blog/migrating-to-typescript/
- https://medium.com/javascript-scene/you-might-not-need-typescript-or-static-types-aa7cb670a77b
- vs. flow https://twitter.com/housecor/status/911673327240073216
- https://engineering.tumblr.com/post/165261504692/flow-and-typescript
- https://medium.com/javascript-scene/the-shocking-secret-about-static-types-514d39bf30a3
- https://slack.engineering/typescript-at-slack-a81307fa288d
- https://redditblog.com/2017/06/30/why-we-chose-typescript/
- https://eng.lyft.com/typescript-at-lyft-64f0702346ea
- https://blog.acolyer.org/2017/09/19/to-type-or-not-to-type-quantifying-detectable-bugs-in-javascript/
- used by Slack https://slack.engineering/growing-pains-migrating-slacks-desktop-app-to-browserview-2759690d9c7b
Bonnes pratiques
- https://www.semver-ts.org/
- https://github.com/labs42io/clean-code-typescript
- https://blog.logrocket.com/when-to-use-never-and-unknown-in-typescript-5e4d6c5799ad/
Ecosystème
https://github.com/typescript-eslint/typescript-eslint
yarn add -D typescript tslib
yarn add -D tslint ts-node eslint typescript-eslint-parser prettier
yarn add -D typescript-string-enums tsmonad
yarn add -D @types/node
fichiers .ts ou .tsx
- https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
- https://www.typescriptlang.org/docs/handbook/compiler-options.html
- interfaces, types
- making sense of types (2023) https://blog.thoughtspile.tech/2023/01/23/typescript-sets/
- basic types :
boolean
number
string
-
void
(for function returns) can only be null or undefinedlet unusable: void = undefined;
Function
- complex
- enum
enum Color {Red, Green, Blue}; let c: Color = Color.Green;
- any
let notSure: any = 4;
let list: any[] = [1, true, "free"];
- enum
- multiple
- array
string[]
ouArray<string>
matrixnumber[][]
- tuple
[string, number]
- union
padding: string | number
- array
- object
- optional values
{a: string, b?: number}
- enforcing key type
{ [k: string]: string }
- optional values
Exemple: JSON Object (https://github.com/Microsoft/TypeScript/issues/1897)
interface JSONObject {
[k: string]: string | number | boolean | null | JSONArray | JSONObject
}
interface JSONArray extends Array<string | number | boolean | JSONObject | JSONArray> { }
let x: string;
let y: [string, number];
let strLength: number = (someValue as string).length;
cast forcé
return (call to api...) as any as Promise<Foo>
function printLabel(labelledObj: { label: string }) {
console.log(labelledObj.label);
}
let myObj = {size: 10, label: "Size 10 Object"};
printLabel(myObj);
interface LabelledValue {
label: string;
}
function printLabel(labelledObj: LabelledValue) {
console.log(labelledObj.label);
}
let myObj = {size: 10, label: "Size 10 Object"};
printLabel(myObj);
type DummyMember = {
email?: string
name: string
admin?: boolean
}
function status(params: { auth: Auth, teamId: string }): Promise<StatusResult> {
...
}
- satisfies https://twitter.com/mattpocockuk/status/1631249088795533315 https://dev.to/tmlr/til-get-strongly-typed-http-headers-with-typescript-3e33
base: declare module 'murmurhash3js-revisited'
augmentation technique: http://ideasintosoftware.com/typescript-module-augmentation-vs-declaration/
- Perf/Optim https://github.com/microsoft/TypeScript/wiki/Performance
- https://www.freecodecamp.org/news/typescript-curry-ramda-types-f747e99744ab/
- method overloading https://medium.com/@kevinkreuzer/typescript-method-overloading-c256dd63245a
- https://codemix.com/opaque-types-in-javascript/
- (deprecated in typescript 2) https://github.com/typings/typings
- A utility built on TSLint for linting TypeScript declaration (.d.ts) files. https://github.com/microsoft/dtslint
https://palantir.github.io/tslint/
- all rules http://palantir.github.io/tslint/rules/
- base rules https://github.com/palantir/tslint/tree/master/src/configs
{
"extends": "tslint:latest",
"rules": {
"comment-format": false,
...
}
}
- https://github.com/cbowdon/TsMonad
- TJSON https://tonyarcieri.com/introducing-tjson-a-stricter-typed-form-of-json
- https://github.com/typestyle/typestyle
- https://github.com/raphaelfeng/typescript-state-machine
- https://github.com/pelotom/runtypes
- TypeScript String Enums
npm install --save typescript-string-enums
import { Enum } from "typescript-string-enums"
export const Status = Enum("RUNNING", "STOPPED")
export type Status = Enum<typeof Status>
- Unionize https://github.com/pelotom/unionize
should target="ES6" + having ES6 in lib[] (default)
bug. Either:
npm i -D @types/node
"lib": "DOM"
declare const console: any;
Requiring directly a file from outside of the package. (maybe auto-added by IDE?)
add tslib...