@skypilot/common-types

A library of reusable common types for TypeScript projects
Exports
Emulation types
interface Class<T> extends Function {
new(...args: any[]): T
}
type Enum<E> = Record<keyof E, number | string> & { [key: number]: string }
type Primitive = boolean | number | string;
JSON types
interface DefiniteJsonArray extends Array<DefiniteJsonValue> {}
type DefiniteJsonMap = {
[key: string]: DefiniteJsonArray | DefiniteJsonMap | JsonPrimitive;
}
type DefiniteJsonValue = DefiniteJsonArray | DefiniteJsonMap | JsonPrimitive;
interface JsonArray extends Array<JsonValue> {}
type JsonMap = {
[key: string]: JsonArray | JsonMap | JsonPrimitive | undefined;
}
type JsonPrimitive = boolean | number | string | null;
type JsonValue = JsonArray | JsonMap | JsonPrimitive | undefined;
Pseudo-types
These types provide semantic value only. (Until TypeScript allows pattern-matching, the patterns
these types imply will not be enforced.)
type Email = string
type Integer = number
type Json = string
type Timestamp = Integer
type Url = string
Utility types
AtLeastOne<T>
: constructs a type that requires at least one property of T
ExactlyOne<T>
: constructs a type that requires exactly one property of T
Maybe<T>
: constructs a type that allows T
, null
, or undefined
MaybeNull<T>
: constructs a type that allows T
or null
MaybeReadOnly<T>
: constructs a type that allows T[]
or readonly T[]
MaybeUndefined<T>
: constructs a type that allows T
or undefined
Require<T, Required>
[DEPRECATED in favor of RequireProps
]: constructs a type that makes the
Required
properties of T
required
RequireProps<T, Required>
: constructs a type that makes the Required
properties of T
required