npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typescript-generic-types

v1.0.1

Published

Generic types for typescript

Downloads

216

Readme

typescript-generic-types

Just import 'typescript-generic-types' on a top of any files in your project.

It will expose global typescript generic types:



type MaybeArray<T> = T | T[]
type MaybePromise<T> = T | Promise<T>

type FunctionGeneric = (...params: any[]) => any
type ObjectGeneric = { [k: string]: any }

type ObjectWithNoFn = { [name: string]: NotFunction<any> }

type NotFunction<T>

type AsType<T, Type> = T extends Type ? T : Type

type AsString<T> = AsType<T, string>

type Complete<T> = {
  [P in keyof Required<T>]: T[P];
}

type CountryCodeIso = `${Letters}${Letters}`
type TranslationObj = { [countryIsoCode in CountryCodeIso]?: string }

type Override<T1, T2>

type RecursivePartial<T>

type Letters = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z'

type SimpleNumbers = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11

type ArrayOneOrMore<T>

type RecursiveObjValueType<T, Type>

type TypeObjectValues<Obj extends Record<string, any>, Type>

// https://stackoverflow.com/questions/49580725/is-it-possible-to-restrict-typescript-object-to-contain-only-properties-defined
type NoExtraProperties<T, U extends T = T>
type MakeObjKeysAsNever<K extends keyof any> = { [P in K]: never }

type RemoveTypeFromTuple<T, TypeToRemove>

type GetTypeKeyFromObject<ObjType, Type>

/** Remove object key/values that are of a certain type */
type RemoveTypeFromObj<ObjType, Type>


/** Get keys where the key type (number, string, Symbol...) is of Type */
type GetObjectKeysThatAreOfType<ObjType, Type>

/** Remove Symbol and number from Object type */
type ForceStringKeyObject<Obj extends Record<any, any>>


/** Get all indices of an array as a type. Eg: 0 | 1 | 2... */
type Indices<T extends readonly any[]>

/** Remove Readonly Modifier */
type Writeable<T>
/** Remove Readonly Modifier Recursively */
type DeepWriteable<T>
/** used to type generic function without having to do (...params: any) => any */
type GenericFunction //
/** used like IsObject<ReturnType> extends true ? .... */
type IsObject<T> 

type ReadonlyDeep<T>

/** Equivalent of { myPropA: string, otherProp?: never } | { myPropA?: never, otherProp: string }. This would be written Exclusive<{ myPropA: string },  {  otherProp: string }> */
type Exclusive<
  A extends Record<string, any>,
  B extends Record<string, any>,
  C extends Record<string, any> = {},
  D extends Record<string, any> = {},
  E extends Record<string, any> = {}
>

type WeekDays = 0 | 1 | 2 | 3 | 4 | 5 | 6

type StringAndUnion<T>

type ArrayKeys<Arr extends any[] | readonly any[]>

type Env = 'test' | 'development' | 'production' | 'preprod' | 'build' | 'ci'