{"id":13475447,"url":"https://github.com/uhyo/better-typescript-lib","last_synced_at":"2025-05-14T14:07:52.440Z","repository":{"id":37847243,"uuid":"325283385","full_name":"uhyo/better-typescript-lib","owner":"uhyo","description":"Better TypeScript standard library","archived":false,"fork":false,"pushed_at":"2025-03-18T13:45:06.000Z","size":1751,"stargazers_count":457,"open_issues_count":4,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-06T15:19:22.335Z","etag":null,"topics":["typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/better-typescript-lib","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uhyo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2020-12-29T12:39:21.000Z","updated_at":"2025-04-17T10:05:08.000Z","dependencies_parsed_at":"2024-01-14T04:51:16.307Z","dependency_job_id":"7dbfa086-8903-4820-8811-7f7a263c61d7","html_url":"https://github.com/uhyo/better-typescript-lib","commit_stats":{"total_commits":166,"total_committers":5,"mean_commits":33.2,"dds":"0.15662650602409633","last_synced_commit":"22a82671a3e0b7b84aa0824a30fd75a7c57c30cd"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhyo%2Fbetter-typescript-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhyo%2Fbetter-typescript-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhyo%2Fbetter-typescript-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhyo%2Fbetter-typescript-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uhyo","download_url":"https://codeload.github.com/uhyo/better-typescript-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254159194,"owners_count":22024558,"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":["typescript"],"created_at":"2024-07-31T16:01:20.447Z","updated_at":"2025-05-14T14:07:52.417Z","avatar_url":"https://github.com/uhyo.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# better-typescript-lib\n\nAn alternative TypeScript standard library with better type definitions.\n\n## What is better-typescript-lib?\n\nTypeScript's built-in type definitions are not _very_ type safe. For example, the return type of `JSON.parse` is `any`.\n\n```ts\nconst obj = JSON.parse('{\"foo\": 42}');\n//    ^? any\n\nconst foo: number = obj.fooo; // oops!\n```\n\nAs you know, the `any` type breaks type safety and makes it far easier to introduce bugs.\n\nIf we consider type safety seriously, the return type of `JSON.parse` should be “any value that can be represented in JSON” and operations on such values should be limited until they are further inspected.\n\nThis is why better-typescript-lib uses `JSONData` as the return type of `JSON.parse`.\n\nAlmost all `any` usage in TypeScript's built-in type definitions is replaced with safer types in better-typescript-lib. Also, better-typescript-lib includes other improvements to the type definitions.\n\n## Why better-typescript-lib?\n\nWhy don't we just fix TypeScript's built-in type definitions rather than maintaining a separate package? Actually, most of improvements in better-typescript-lib are unlikely to be accepted by TypeScript's maintainers if presented as possible improvement to TypeScript itself. This is because the improvements are often severe breaking changes to existing codebases.\n\nA large part of `any` usage in TypeScript's built-in type definitions are there before the `unknown` type was introduced in TypeScript 3.0. Back then, there was no good way to represent “any value” in TypeScript's type system and `any` was used as the best approximation. Aside from `any`, there are a lot of possible improvements that became possible as TypeScript evolved.\n\nIn other words, if you don't care about breaking changes (for example, you are starting a new project), you are just suffering from stale type definitions from the old days without getting any benefits from the maintained backward compatibility.\n\nThis is where better-typescript-lib comes in. It is a separate package that can be used in new projects or projects that are willing to fix type errors caused by the improvements.\n\n[You can see the diff from the original TypeScript lib here](./docs/diff.md).\n\n## Installation\n\nYou only need to install `better-typescript-lib`. For npm and yarn, additional configuration is not needed; your TypeScript project automatically starts to use `better-typescript-lib` definitions. For pnpm, see below.\n\n```sh\nnpm i -D better-typescript-lib\n```\n\n[If you are using TypeScript 4.4 or prior, see the v1 branch.](https://github.com/uhyo/better-typescript-lib/tree/v1)\n\n### Set `libReplacement: true`\n\nIf you are using **TypeScript 5.8 or later**, include the following setting in your `tsconfig.json`:\n\n```json\n{\n  \"compilerOptions\": {\n    // ...\n    \"libReplacement\": true\n  }\n}\n```\n\n\u003e [!NOTE]\n\u003e The `libReplacement` option is available from TypeScript 5.8. If you are using TypeScript 5.7 or earlier, better-typescript-lib will work by default.\n\u003e\n\u003e Technically this option is not required for the current version of TypeScript because the default value is `true`. It is recommended to include it for future compatibility. In the following versions of TypeScript (likely 6.0 or later), the default value may be changed to `false` and you will need to set it to `true`.\n\n### How it works\n\nStarting from TypeScript 4.5, the TypeScript compiler detects existence of `@typescript/lib-xxx` packages (e.g. `@typescript/lib-es2015`) and uses them instead of the built-in definitions. By installing `better-typescript-lib`, these package names are mapped to corresponding `@better-typescript-lib/xxx` packages.\n\n### With pnpm\n\nWith pnpm, you need to append the following line to the `.npmrc` file:\n\n```properties\npublic-hoist-pattern[]=@typescript/*\n```\n\nWith pnpm the `@better-typescript-lib/xxx` packages are not installed to `node_modules/@typescript/xxx` without [`public-hoist-pattern`](https://pnpm.io/npmrc#public-hoist-pattern).\n\nThis is because, unlike npm and yarn, by default pnpm does not allow your source code to access dependencies that have not been added to your project as dependencies.\n\n## Supported TypeScript Versions\n\n| better-typescript-lib | TypeScript      |\n| --------------------- | --------------- |\n| 2.11.0                | TS 5.8 or later |\n| 2.10.0                | TS 5.7 or later |\n| 2.9.0                 | TS 5.6 or later |\n| 2.8.0                 | TS 5.5 or later |\n| 2.7.0                 | TS 5.4 or later |\n| 2.6.0                 | TS 5.3 or later |\n| 2.5.0                 | TS 5.2 or later |\n| 2.4.0                 | TS 5.1 or later |\n| 2.3.0                 | TS 5.0 or later |\n| 2.2.0                 | TS 4.9 or later |\n| 2.1.0                 | TS 4.6 or later |\n| 2.0.0                 | TS 4.5 or later |\n\n[If you are using TypeScript 4.4 or prior, see the v1 branch.](https://github.com/uhyo/better-typescript-lib/tree/v1)\n\n## Goals and Non-Goals\n\nBetter-typescript-lib aims to provide better type definitions for TypeScript's standard library. _Better_ means more type safety, therefore they may cause more type errors to existing codebases.\n\nWhile better type definitions are often more convenient to use, this is not always the case. If type safety and convenience are in conflict, better-typescript-lib prioritizes type safety.\n\nAs this is only an alternative to TypeScript's built-in type definitions, we have no plan of providing any runtime implementation through better-typescript-lib.\n\n### Versioning Policy\n\nBetter-typescript-lib is based on TypeScript's standard library. Therefore, a new TypeScript version will be followed by a corresponding better-typescript-lib version. If you want to use a new feature included in a new TypeScript version, you need to use a better-typescript-lib version that supports that TypeScript version.\n\nImprovements to type definitions may be released as a new minor version even if it may cause new type errors to existing codebases. We recommend regularly updating better-typescript-lib to the latest version and fixing type errors caused by the updates.\n\nThis is similar to how TypeScript itself evolves, but better-typescript-lib updates may have more breaking changes than TypeScript itself due to the nature of the improvements.\n\n## Contributing\n\nWelcome\n\n## License\n\nThis work is based on [TypeScript](https://github.com/microsoft/TypeScript)'s standard library created by Microsoft Corporation. We modify it as programmed in this repository and redistribute it under Apache 2.0 License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuhyo%2Fbetter-typescript-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuhyo%2Fbetter-typescript-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuhyo%2Fbetter-typescript-lib/lists"}