{"id":13411037,"url":"https://github.com/danvk/effective-typescript","last_synced_at":"2025-05-14T14:08:35.446Z","repository":{"id":38206338,"uuid":"216239754","full_name":"danvk/effective-typescript","owner":"danvk","description":"Effective TypeScript 2nd Edition: 83 Specific Ways to Improve Your TypeScript","archived":false,"fork":false,"pushed_at":"2024-10-31T15:03:25.000Z","size":24818,"stargazers_count":1659,"open_issues_count":30,"forks_count":239,"subscribers_count":23,"default_branch":"main","last_synced_at":"2025-04-12T02:55:52.542Z","etag":null,"topics":["books","typescript","utterances"],"latest_commit_sha":null,"homepage":"https://effectivetypescript.com","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danvk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-19T16:52:51.000Z","updated_at":"2025-04-08T12:38:33.000Z","dependencies_parsed_at":"2024-01-07T03:40:08.076Z","dependency_job_id":"d2b0538d-1a8d-44ca-9c5f-2428b47de8fc","html_url":"https://github.com/danvk/effective-typescript","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Feffective-typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Feffective-typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Feffective-typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Feffective-typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danvk","download_url":"https://codeload.github.com/danvk/effective-typescript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254159840,"owners_count":22024564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["books","typescript","utterances"],"created_at":"2024-07-30T20:01:10.984Z","updated_at":"2025-05-14T14:08:35.421Z","avatar_url":"https://github.com/danvk.png","language":null,"readme":"[\u003cimg src=\"/cover.jpg\" width=\"286\" title=\"Second Edition Cover Image\" align=\"right\"\u003e][a]\n\n# Effective TypeScript\n\nThis is the code sample repo for the _Effective TypeScript: 83 Specific Ways to Improve Your TypeScript_ (O'Reilly, May 2024). The book is available through:\n\n- [Amazon][a]\n- [O'Reilly][o]\n- [DRM-Free eBook][ebook]\n\nand others. You can get the latest updates on the book at [effectivetypescript.com](https://effectivetypescript.com).\n\nStill on the first edition? Check out the [`1st-edition` branch][1e].\n\n## Code Samples\n\nBelow you'll find a complete table of contents. Each item links to a page with its \"Things to Remember\" (a short summary of the item) and a listing of all its code samples. The code samples are accompanied by links to the [TypeScript playground][play]. They should produce the expected errors (and no others) and expected types.\n\nUnless otherwise noted in a comment at the top of the code sample, the samples are run with TypeScript's `strict` setting. These were produced and checked using [literate-ts][] and TypeScript 5.4.5.\n\n- **Chapter 1: Getting to Know TypeScript**\n  - [:memo: Item 1](/samples/ch-intro/ts-vs-js.md): Understand the Relationship Between TypeScript and JavaScript\n  - [:memo: Item 2](/samples/ch-intro/which-ts.md): Know Which TypeScript Options You're Using\n  - [:memo: Item 3](/samples/ch-intro/independent.md): Understand That Code Generation Is Independent of Types\n  - [:memo: Item 4](/samples/ch-intro/structural.md): Get Comfortable with Structural Typing\n  - [:memo: Item 5](/samples/ch-intro/any.md): Limit Use of the `any` Type\n\n- **Chapter 2: TypeScript's Type System**\n  - [:memo: Item 6](/samples/ch-types/editor.md): Use Your Editor to Interrogate and Explore the Type System\n  - [:memo: Item 7](/samples/ch-types/types-as-sets.md): Think of Types as Sets of Values\n  - [:memo: Item 8](/samples/ch-types/type-value-space.md): Know How to Tell Whether a Symbol Is in the Type Space or Value Space\n  - [:memo: Item 9](/samples/ch-types/prefer-declarations-to-assertions.md): Prefer Type Annotations to Type Assertions\n  - [:memo: Item 10](/samples/ch-types/avoid-object-wrapper-types.md): Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)\n  - [:memo: Item 11](/samples/ch-types/excess-property-checking.md): Distinguish Excess Property Checking from Type Checking\n  - [:memo: Item 12](/samples/ch-types/type-entire-functions.md): Apply Types to Entire Function Expressions When Possible\n  - [:memo: Item 13](/samples/ch-types/type-vs-interface.md): Know the Differences Between `type` and `interface`\n  - [:memo: Item 14](/samples/ch-types/readonly.md): Use `readonly` to Avoid Errors Associated with Mutation\n  - [:memo: Item 15](/samples/ch-types/map-between-types.md): Use Type Operations and Generic Types to Avoid Repeating Yourself\n  - [:memo: Item 16](/samples/ch-types/index-for-dynamic.md): Prefer More Precise Alternatives to Index Signatures\n  - [:memo: Item 17](/samples/ch-types/number-index.md): Avoid Numeric Index Signatures\n\n- **Chapter 3: Type Inference and Control Flow Analysis**\n  - [:memo: Item 18](/samples/ch-inference/avoid-inferable.md): Avoid Cluttering Your Code with Inferable Types\n  - [:memo: Item 19](/samples/ch-inference/one-var-one-type.md): Use Different Variables for Different Types\n  - [:memo: Item 20](/samples/ch-inference/widening.md): Understand How a Variable Gets Its Type\n  - [:memo: Item 21](/samples/ch-inference/all-at-once.md): Create Objects All at Once\n  - [:memo: Item 22](/samples/ch-inference/narrowing.md): Understand Type Narrowing\n  - [:memo: Item 23](/samples/ch-inference/avoid-aliasing.md): Be Consistent in Your Use of Aliases\n  - [:memo: Item 24](/samples/ch-inference/context-inference.md): Understand How Context Is Used in Type Inference\n  - [:memo: Item 25](/samples/ch-inference/evolving-any.md): Understand Evolving Types\n  - [:memo: Item 26](/samples/ch-inference/functional-libraries.md): Use Functional Constructs and Libraries to Help Types Flow\n  - [:memo: Item 27](/samples/ch-inference/use-async-await.md): Use async Functions Instead of Callbacks to Improve Type Flow\n  - [:memo: Item 28](/samples/ch-inference/inference-sites.md): Use Classes and Currying to Create New Inference Sites\n\n- **Chapter 4: Type Design**\n  - [:memo: Item 29](/samples/ch-design/valid-states.md): Prefer Types That Always Represent Valid States\n  - [:memo: Item 30](/samples/ch-design/loose-accept-strict-produce.md): Be Liberal in What You Accept and Strict in What You Produce\n  - [:memo: Item 31](/samples/ch-design/jsdoc-repeat.md): Don’t Repeat Type Information in Documentation\n  - [:memo: Item 32](/samples/ch-design/null-in-type.md): Avoid Including `null` or `undefined` in Type Aliases\n  - [:memo: Item 33](/samples/ch-design/null-values-to-perimeter.md): Push Null Values to the Perimeter of Your Types\n  - [:memo: Item 34](/samples/ch-design/union-of-interfaces.md): Prefer Unions of Interfaces to Interfaces with Unions\n  - [:memo: Item 35](/samples/ch-design/avoid-strings.md): Prefer More Precise Alternatives to String Types\n  - [:memo: Item 36](/samples/ch-design/in-domain-null.md): Use a Distinct Type for Special Values\n  - [:memo: Item 37](/samples/ch-design/avoid-optional.md): Limit the Use of Optional Properties\n  - [:memo: Item 38](/samples/ch-design/same-type-params.md): Avoid Repeated Parameters of the Same Type\n  - [:memo: Item 39](/samples/ch-design/unify.md): Prefer Unifying Types to Modeling Differences\n  - [:memo: Item 40](/samples/ch-design/incomplete-over-inaccurate.md): Prefer Imprecise Types to Inaccurate Types\n  - [:memo: Item 41](/samples/ch-design/language-of-domain.md): Name Types Using the Language of Your Problem Domain\n  - [:memo: Item 42](/samples/ch-design/consider-codegen.md): Avoid Types Based on Anecdotal Data\n\n- **Chapter 5: Unsoundness and the any Type**\n  - [:memo: Item 43](/samples/ch-any/narrowest-any.md): Use the Narrowest Possible Scope for `any` Types\n  - [:memo: Item 44](/samples/ch-any/specific-any.md): Prefer More Precise Variants of `any` to Plain `any`\n  - [:memo: Item 45](/samples/ch-any/hide-unsafe-casts.md): Hide Unsafe Type Assertions in Well-Typed Functions\n  - [:memo: Item 46](/samples/ch-any/never-unknown.md): Use unknown Instead of `any` for Values with an Unknown Type\n  - [:memo: Item 47](/samples/ch-any/type-safe-monkey.md): Prefer Type-Safe Approaches to Monkey Patching\n  - [:memo: Item 48](/samples/ch-any/unsoundness.md): Avoid Soundness Traps\n  - [:memo: Item 49](/samples/ch-any/type-percentage.md): Track Your Type Coverage to Prevent Regressions in Type Safety\n\n- **Chapter 6: Generics and Type-Level Programming**\n  - [:memo: Item 50](/samples/ch-generics/functions-on-types.md): Think of Generics as Functions Between Types\n  - [:memo: Item 51](/samples/ch-generics/golden-rule.md): Avoid Unnecessary Type Parameters\n  - [:memo: Item 52](/samples/ch-generics/conditional-overload.md): Prefer Conditional Types to Overload Signatures\n  - [:memo: Item 53](/samples/ch-generics/control-distribution.md): Know How to Control the Distribution of Unions over Conditional Types\n  - [:memo: Item 54](/samples/ch-generics/template-dsl.md): Use Template Literal Types to Model DSLs and Relationships Between Strings\n  - [:memo: Item 55](/samples/ch-generics/test-your-types.md): Write Tests for Your Types\n  - [:memo: Item 56](/samples/ch-generics/type-display.md): Pay Attention to How Types Display\n  - [:memo: Item 57](/samples/ch-generics/tail-recursion.md): Prefer Tail-Recursive Generic Types\n  - [:memo: Item 58](/samples/ch-generics/codegen-alt.md): Consider Codegen as an Alternative to Complex Types\n\n- **Chapter 7: TypeScript Recipes**\n  - [:memo: Item 59](/samples/ch-recipes/exhaustiveness.md): Use `never` Types to Perform Exhaustiveness Checking\n  - [:memo: Item 60](/samples/ch-recipes/iterate-objects.md): Know How to Iterate Over Objects\n  - [:memo: Item 61](/samples/ch-recipes/values-in-sync.md): Use `Record` Types to Keep Values in Sync\n  - [:memo: Item 62](/samples/ch-recipes/conditional-varargs.md): Use Rest Parameters and Tuple Types to Model Variadic Functions\n  - [:memo: Item 63](/samples/ch-recipes/optional-never.md): Use Optional `never` Properties to Model Exclusive Or\n  - [:memo: Item 64](/samples/ch-recipes/brands.md): Consider Brands for Nominal Typing\n\n- **Chapter 8: Type Declarations and @types**\n  - [:memo: Item 65](/samples/ch-declarations/dev-dependencies.md): Put TypeScript and `@types` in `devDependencies`\n  - [:memo: Item 66](/samples/ch-declarations/three-versions.md): Understand the Three Versions Involved in Type Declarations\n  - [:memo: Item 67](/samples/ch-declarations/export-your-types.md): Export All Types That Appear in Public APIs\n  - [:memo: Item 68](/samples/ch-declarations/use-tsdoc.md): Use TSDoc for API Comments\n  - [:memo: Item 69](/samples/ch-declarations/this-in-callbacks.md): Provide a Type for `this` in Callbacks if It's Part of Their API\n  - [:memo: Item 70](/samples/ch-declarations/mirror-types-for-deps.md): Mirror Types to Sever Dependencies\n  - [:memo: Item 71](/samples/ch-declarations/augment-improve.md): Use Module Augmentation to Improve Types\n\n- **Chapter 9: Writing and Running Your Code**\n  - [:memo: Item 72](/samples/ch-write-run/avoid-non-ecma.md): Prefer ECMAScript Features to TypeScript Features\n  - [:memo: Item 73](/samples/ch-write-run/source-maps-debug.md): Use Source Maps to Debug TypeScript\n  - [:memo: Item 74](/samples/ch-write-run/runtime-types.md): Know How to Reconstruct Types at Runtime\n  - [:memo: Item 75](/samples/ch-write-run/understand-the-dom.md): Understand the DOM Hierarchy\n  - [:memo: Item 76](/samples/ch-write-run/model-env.md): Create an Accurate Model of Your Environment\n  - [:memo: Item 77](/samples/ch-write-run/types-or-tests.md): Understand the Relationship Between Type Checking and Unit Testing\n  - [:memo: Item 78](/samples/ch-write-run/performance.md): Pay Attention to Compiler Performance\n\n- **Chapter 10: Modernization and Migration**\n  - [:memo: Item 79](/samples/ch-migrate/write-modern-js.md): Write Modern JavaScript\n  - [:memo: Item 80](/samples/ch-migrate/jsdoc-tscheck.md): Use `@ts-check` and JSDoc to Experiment with TypeScript\n  - [:memo: Item 81](/samples/ch-migrate/allowjs.md): Use `allowJs` to Mix TypeScript and JavaScript\n  - [:memo: Item 82](/samples/ch-migrate/convert-up-the-graph.md): Convert Module by Module Up Your Dependency Graph\n  - [:memo: Item 83](/samples/ch-migrate/start-loose.md): Don't Consider Migration Complete Until You Enable `noImplicitAny`\n\n[o]: https://www.oreilly.com/library/view/effective-typescript/9781098155056/\n[a]: https://amzn.to/3UjPrsK\n[ebook]: https://www.ebooks.com/search/?term=9781098155063\u0026affid=OMI5374258\n[literate-ts]: https://github.com/danvk/literate-ts\n[play]: https://www.typescriptlang.org/play/\n[1e]: https://github.com/danvk/effective-typescript/tree/1st-edition\n","funding_links":[],"categories":["Others","miscellaneous","Programming languages"],"sub_categories":["TypeScript"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanvk%2Feffective-typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanvk%2Feffective-typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanvk%2Feffective-typescript/lists"}