{"id":12243,"library":"typescript-miscellaneous","title":"TypeScript Miscellaneous Utilities","description":"The `typescript-miscellaneous` package offers a collection of advanced TypeScript utility types designed to simplify complex type manipulations and enhance type safety within TypeScript projects. Currently at version 0.1.1, it provides specialized types such as `Dict` for creating flexible dictionary-like structures, `UnionToIntersection` for converting union types into intersection types, `ElementOf` for inferring element types from array or tuple types, and `ParametersOf` and `ReturnOf` for extracting function signature components. As a focused utility library, its release cadence is typically infrequent, prioritizing stability and correctness over rapid feature expansion. It distinguishes itself by providing pre-built, reusable type constructs that address common, yet often complex, TypeScript type challenges, thereby reducing boilerplate and improving developer productivity.","status":"active","version":"0.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/ksxnodemodules/typescript-miscellaneous","tags":["javascript","typescript","miscellaneous","utility"],"install":[{"cmd":"npm install typescript-miscellaneous","lang":"bash","label":"npm"},{"cmd":"yarn add typescript-miscellaneous","lang":"bash","label":"yarn"},{"cmd":"pnpm add typescript-miscellaneous","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for type checking and compilation, specifies minimum compatible TypeScript version.","package":"typescript","optional":false}],"imports":[{"note":"This is a TypeScript type export and cannot be imported or used as a runtime value. Attempting to use `require` will result in a runtime error or a type-related compilation failure.","wrong":"const Dict = require('typescript-miscellaneous').Dict;","symbol":"Dict","correct":"import { Dict } from 'typescript-miscellaneous';"},{"note":"This is a TypeScript type export, used for compile-time type manipulation. It has no runtime representation and cannot be imported via `require`.","wrong":"const UnionToIntersection = require('typescript-miscellaneous').UnionToIntersection;","symbol":"UnionToIntersection","correct":"import { UnionToIntersection } from 'typescript-miscellaneous';"},{"note":"While importing the entire module might work for types in some configurations, the direct named import `import { ElementOf } from 'typescript-miscellaneous';` is the idiomatic and clearer way for type-only imports.","wrong":"import * as Lib from 'typescript-miscellaneous'; type El = Lib.ElementOf<any>;","symbol":"ElementOf","correct":"import { ElementOf } from 'typescript-miscellaneous';"}],"quickstart":{"code":"import { Dict, ElementOf, ParametersOf, ReturnOf } from 'typescript-miscellaneous';\n\n// Example 1: Dict - create a dictionary-like type with mixed keys and values\ntype MyComplexDict = Dict<\n  'id' | 'name' | 'age' | 0 | 1,\n  string | number\n>;\n\nconst user: MyComplexDict = {\n  id: 'uuid-123',\n  name: 'Alice',\n  age: 30,\n  0: 'first_val',\n  1: 123\n};\n\nconsole.log(`User ID: ${user.id}, Age: ${user.age}`);\n\n// Example 2: ElementOf - extract the union type of elements from an array/tuple\ntype Colors = ['red', 'green', 'blue'];\ntype Color = ElementOf<Colors>; // Expected: 'red' | 'green' | 'blue'\n\nconst favoriteColor: Color = 'green';\n// const invalidColor: Color = 'yellow'; // This would correctly cause a TypeScript error\n\nconsole.log(`Favorite color: ${favoriteColor}`);\n\n// Example 3: ParametersOf and ReturnOf - infer parts of a function signature\nfunction greet(name: string, age: number): string {\n  return `Hello, ${name}! You are ${age} years old.`;\n}\n\ntype GreetParams = ParametersOf<typeof greet>; // Expected: [name: string, age: number]\ntype GreetReturn = ReturnOf<typeof greet>;   // Expected: string\n\nconst params: GreetParams = ['Bob', 25];\nconst greeting: GreetReturn = greet(...params);\n\nconsole.log(greeting);\n","lang":"typescript","description":"This quickstart demonstrates the usage of `Dict` for creating flexible object types, `ElementOf` for inferring types from tuples/arrays, and `ParametersOf`/`ReturnOf` for extracting function signature details."},"warnings":[{"fix":"Upgrade your project's TypeScript dependency to version 3.0.0 or newer in `package.json` and ensure your `tsconfig.json` targets an appropriate ES version.","message":"This library explicitly requires TypeScript version 3.0.0 or higher. Using it with older TypeScript compilers will result in compilation errors due to reliance on newer type system features.","severity":"breaking","affected_versions":"<3.0.0"},{"fix":"Pin the exact version (e.g., `0.1.1`) or a compatible range (e.g., `^0.1.0`) in your `package.json` and regularly review release notes for updates.","message":"As a library in its 0.x.x version, the API surface might undergo breaking changes in minor or patch releases before a stable 1.0.0 version is published. Always review the changelog when upgrading.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Optimize other parts of your TypeScript configuration, consider breaking down overly complex types, or use performance profiling tools for TypeScript compilation to identify bottlenecks.","message":"Advanced utility types, especially when deeply nested or heavily composed, can sometimes lead to increased TypeScript compilation times and memory usage. Monitor build performance in large codebases.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Simplify surrounding types, provide explicit type arguments where inference struggles, or consult the TypeScript documentation for advanced type compatibility rules.","message":"Some complex type manipulations might result in unexpected type inference behavior when combined with other highly generic types or specific TypeScript strictness settings. Debug type issues using TypeScript's `--traceResolution` or IDE type inspection tools.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Add the necessary import statement: `import { Dict } from 'typescript-miscellaneous';` (or the specific type you are using).","cause":"The utility type was not imported into the current file.","error":"Cannot find name 'Dict'."},{"fix":"Carefully review the documentation for the specific utility type you are using and ensure your input types and usage patterns align with its expected behavior.","cause":"An incorrect input type was provided to one of the utility types, or the resulting type was misused.","error":"Type 'X' is not assignable to type 'Y'."},{"fix":"Ensure your `tsconfig.json` `moduleResolution` is set to `node` or `bundler` and `allowSyntheticDefaultImports` and `esModuleInterop` are enabled if using default imports (though this library primarily uses named type imports). Avoid adding `.js` extensions to type import paths.","cause":"This package primarily exports TypeScript types. While the error might be generic to module resolution, it could imply misconfiguration if you're trying to import types from a `.js` output or incorrectly configuring module resolution for type files.","error":"An import path cannot end with a '.js' extension when 'resolveJsonModule' is enabled. Consider importing 'foo' instead."}],"ecosystem":"npm"}