Package Exports
- @ergodark/types
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ergodark/types) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@ergodark/types
This package contains various utility and helper types that can be imported by a TypeScript project.
This package only contains TypeScript types.
Install
npm install @ergodark/typesUsage
You can use this library's types in your TypeScript projects like so:
import type { TypeNameHere } from '@ergodark/types'
const variable: TypeNameHere;import type * as ErgoDark from '@ergodark/types'
const variable: ErgoDark.TypeNameHere;Type Glossary
This library provides the following types:
- Primitive
- Falsy
- Nullish
- DeepPartial<T>
- AnyKey
- AnyFunction
- AnyConstructor
- AnyClass
- AnyRecord
- Awaited<T>
- HttpStatusCode
Primitive
Represents all "primitive" types. Specifically: string, number, bigint,
boolean, symbol, null, and undefined.
import type { Primitive } from '@ergodark/types'
let primitive: Primitive = "yes";
primitive = 1;
primitive = Symbol('yes');
primitive = null;
primitive = new Date(); // <== TypeScript errorFalsy
Represents all "falsy" types. Specifically: false, '', 0, null, and
undefined.
import type { Falsy } from '@ergodark/types'
let falsy: Falsy = "";
falsy = 0;
falsy = false;
falsy = null;
falsy = true; // <== TypeScript errorNullish
Represents all "nullish" types. Specifically: null and undefined.
import type { Nullish } from '@ergodark/types'
let nullish: Nullish = null;
nullish = undefined;
nullish = true; // <== TypeScript errorDeepPartial<T>
TypeScript's
Partial
import type { DeepPartial } from '@ergodark/types'
type T = { a: string, b: { c: { d: number }}};
let t:T = { a: "enough!", b: { c: { d: 1 }}};
let t_bad:T = { a: "enough?" }; // <== TypeScript error
let t2:Partial<T> = { a: "enough?" };
let t2_bad:Partial<T> = { a: "enough?", b: {}}; // <== TypeScript error
let t3:DeepPartial<T> = { a: "enough?" };
let t3_ok:DeepPartial<T> = { a: "enough?", b: {}};AnyKey
Represents any possible object key.
import type { AnyKey } from '@ergodark/types'
let key: AnyKey = "key";
key = Symbol('key');
key = true; // <== TypeScript errorAnyFunction
Represents any possible function.
import type { AnyFunction } from '@ergodark/types'
let fn: AnyFunction = () => true;
fn = Symbol('key'); // <== TypeScript errorAnyConstructor
Represents any possible constructor.
import type { AnyConstructor } from '@ergodark/types'
let myConstructor: AnyConstructor = Date;
myConstructor = Symbol('key'); // <== TypeScript errorAnyClass
Represents any possible class.
import type { AnyClass } from '@ergodark/types'
let MyClass: AnyClass = class { bark() { return 'woof!' }};
MyClass = Symbol('key'); // <== TypeScript errorAnyRecord
Represents any object with string keys. Alias of Record<string, unknown>.
import type { AnyRecord } from '@ergodark/types'
let record: AnyRecord = { a: 1 };
record = Symbol('key'); // <== TypeScript errorAwaited<T>
Recursively unwrap the return value of a resolved promise.
import type { Awaited } from '@ergodark/types'
const p1 = new Promise<boolean>(resolve => resolve(true));
const p2 = new Promise<typeof p1>(resolve => resolve(p1));
// Type of `p2` is Promise<Promise<boolean>> ...
let result: Awaited<typeof p2>; // <== However, type of `result` is booleanHttpStatusCode
Represents any valid (and a few invalid) HTTP status code.
import fetch from 'isomorphic-unfetch'
import type { HttpStatusCode } from '@ergodark/types'
const res = await fetch('https://google.com');
const status: HttpStatusCode = res.status;Contributing
Issues and pull requests are welcome! In lieu of a formal styleguide, take care to maintain the existing coding style.
Please test your code!
Release History
- 1.0.x Initial release