![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
simplytyped
Advanced tools
Yet another typing library. This differs by aiming to be less experimental than others, driven by industry use cases.
Many of the exposed types are a very thin layer above built in functionality. The goal is to provide all of the building blocks necessary to make concise, yet complex types.
Some (somewhat common) implementations of conditional type logic
type x = If<True, string, number> // => string
type y = If<False, string, number> // => number
type x = If<And<True, True>, string, number> // => string
type y = If<And<True, False>, string, number> // => number
...
type x = If<Or<True, False>, string, number> // => string
type y = If<Or<False, False>, string, number> // => number
...
type x = Not<True> // => False
type y = Not<False> // => True
type x = Xor<True, False> // => True
type y = Xor<True, True> // => False
...
type x = Nand<True, True> // => False
type y = Nand<False, True> // => True
type obj1 = { w: string, x: string, y: number }
type obj2 = { y: string, z: number }
No different than keyof
, but can look a bit nicer when nesting many types deep
type x = keyof obj1 // => 'w' | 'x' | 'y'
type y = Keys<obj1> // => 'w' | 'x' | 'y'
On its own, not that interesting.
Takes an object and makes it an object type.
Is useful when combined with &
intersection types (as seen next).
type x = ObjectType<obj1> // => { w: string, x: string, y: number }
Takes the intersection between two objects, and flattens them. This can make extremely complex types look much nicer.
type x = obj1 & obj2 // => { w: string, x: string, y: number } & { y: string, z: number }
type y = CombineObjects<obj1, obj2> // => { w: string, x: string, y: string & number, z: number }
Gets all of the keys that are shared between two objects (as in keys in common).
type x = SharedKeys<obj1, obj2> // => 'y'
Gets all of the keys that are different from obj1 to obj2.
type x = DiffKeys<obj1, obj2> // => 'w' | 'x'
type y = DiffKeys<obj2, obj1> // => 'z'
Gets all keys between two objects.
type x = AllKeys<obj1, obj2> // => 'w' | 'x' | 'y' | 'z'
Gives back an object with listed keys removed.
type x = Omit<obj1, 'w' | 'x'> // => { y: number }
Much like _.merge
in javascript, this returns an object with all keys present between both objects, but conflicts resolved by rightmost object.
type x = Merge<obj1, obj2> // => { w: string, x: string, y: string, z: number }
Uses Partial
to make every parameter of an object optional (| undefined
).
type x = DeepPartial<obj1> // => { w?: string, x?: string, y?: number }
A tuple can be defined in two ways: [number, string]
which as of Typescript 2.7 has an enforced length type parameter: [number, string]['length'] === 2
or using this libraries Tuple<any>
which can be extended with any length of tuple: function doStuff<T extends Tuple<any>>(x: T) {}
.
function doStuff<T extends Tuple<any>>(x: T) {}
doStuff(['hi', 'there']); // => doStuff(x: ['hi', 'there']): void
type x = UnionizeTuple<[number, string]> // => number | string
Get the differences between two unions of strings.
type x = Diff<'hi' | 'there', 'hi' | 'friend'> // => 'there'
FAQs
yet another Typescript type library for advanced types
The npm package simplytyped receives a total of 4,782 weekly downloads. As such, simplytyped popularity was classified as popular.
We found that simplytyped demonstrated a not healthy version release cadence and project activity because the last version was released 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.