Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
type-fest
Advanced tools
The type-fest package provides a collection of essential TypeScript types for use in a wide range of applications. It includes utility types, primitive types, and complex object types to enhance TypeScript's static typing capabilities.
Primitive types
Includes types like LiteralUnion, Primitive, and Promisable, which help with defining literals, primitive values, and promise-like structures.
{"isPrimitive": true}
Basic utilities
Provides utility types such as Except, Mutable, ReadonlyDeep, and many others that help manipulate and transform types in various ways.
{"isEmptyArray": array.length === 0}
Object types
Contains types for working with objects, such as Merge and RequireAtLeastOne, which assist in merging types and ensuring at least one property is present, respectively.
{"isObjectClean": Object.keys(object).length === 0 && object.constructor === Object}
Conditional types
Includes conditional types like ConditionalExcept and ConditionalKeys, which apply conditions to filter keys or properties of types.
{"isTruthy": T extends false | '' | 0 | null | undefined ? false : true}
The utility-types package provides a collection of utility types for TypeScript, similar to type-fest. It includes types for operations like picking, omitting, and readonly transformations. It is comparable to type-fest but may have a different set of utilities and slightly different implementations.
ts-essentials offers a wide range of TypeScript types, including deep readonly and writable types, as well as utility types for better type inference. It is similar to type-fest in its goal to enhance TypeScript's type system but may differ in the specific types offered and its API design.
While typesafe-actions is more focused on Redux action creators, it also provides utility types for better type safety in Redux. It is similar to type-fest in that it enhances TypeScript's type system but is more specialized for Redux-related typing.
Many of the types here should have been built-in. You can help by suggesting some of them to the TypeScript project.
Either add this package as a dependency or copy-paste the needed types. No credit required. 👌
PR welcome for additional commonly needed types and docs improvements. Read the contributing guidelines first.
$ npm install type-fest
Requires TypeScript >=3.2
import {Omit} from 'type-fest';
type Foo = {
unicorn: string;
rainbow: boolean;
};
type FooWithoutRainbow = Omit<Foo, 'rainbow'>;
//=> {unicorn: string}
Click the type names for complete docs.
Primitive
- Matches any primitive value.Class
- Matches a class
constructor.TypedArray
- Matches any typed array, like Uint8Array
or Float64Array
.JsonObject
- Matches a JSON object.JsonArray
- Matches a JSON array.JsonValue
- Matches any valid JSON value.ObservableLike
- Matches a value that is like an Observable.Omit
- Create a type from an object type without certain keys.Mutable
- Convert an object with readonly
properties into a mutable object. Inverse of Readonly<T>
.Merge
- Merge two types into a new type. Keys of the second type overrides keys of the first type.MergeExclusive
- Create a type that has mutually exclusive properties.RequireAtLeastOne
- Create a type that requires at least one of the given properties.ReadonlyDeep
- Create a deeply immutable version of a object
/Map
/Set
/Array
type.LiteralUnion
- Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union. Workaround for Microsoft/TypeScript#29729.PackageJson
- Type for npm's package.json
file.If we decline a type addition, we will make sure to document the better solution here.
Diff
and Spread
- The PR author didn't provide any real-world use-cases and the PR went stale. If you think this type is useful, provide some real-world use-cases and we might reconsider.There are many advanced types most users don't know about.
Partial<T>
- Make all properties in T
optional.Required<T>
- Make all properties in T
required.Readonly<T>
- Make all properties in T
readonly.Pick<T, K>
- From T
, pick a set of properties whose keys are in the union K
.Record<K, T>
- Construct a type with a set of properties K
of type T
.Exclude<T, U>
- Exclude from T
those types that are assignable to U
.Extract<T, U>
- Extract from T
those types that are assignable to U
.NonNullable<T>
- Exclude null
and undefined
from T
.Parameters<T>
- Obtain the parameters of a function type in a tuple.ConstructorParameters<T>
- Obtain the parameters of a constructor function type in a tuple.ReturnType<T>
– Obtain the return type of a function type.InstanceType<T>
– Obtain the instance type of a constructor function type.You can find some examples in the TypeScript docs.
(MIT OR CC0-1.0)
FAQs
A collection of essential TypeScript types
The npm package type-fest receives a total of 64,759,869 weekly downloads. As such, type-fest popularity was classified as popular.
We found that type-fest demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.