Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
typelevel-ts
Advanced tools
Requires TypeScript v2.4.1+
Adapted from
Nat
uralsExample. Type-safe vectors
import { _1, _2, _3, Nat, Add } from 'typelevel-ts'
function create<A>(as: [A, A, A]): Vector<_3, A>
function create<A>(as: [A, A]): Vector<_2, A>
function create<A>(as: [A]): Vector<_1, A>
function create<N extends Nat, A>(as: Array<A>): Vector<N, A> {
return new Vector<N, A>(as)
}
class Vector<N extends Nat, A> {
static create = create
readonly _N: N
readonly _A: A
constructor(public value: Array<A>) {}
append<N2 extends Nat>(vector: Vector<N2, A>): Vector<Add<N, N2>, A> {
return new Vector<Add<N, N2>, A>(this.value.concat(vector.value))
}
zip<B>(vector: Vector<N, B>): Vector<N, [A, B]> {
return new Vector<N, [A, B]>(this.value.map((a, i) => [a, vector.value[i]] as [A, B]))
}
inspect() {
return this.toString()
}
toString() {
return `Vector(${JSON.stringify(this.value)})`
}
}
// v1 :: Vector<_1, number>
const v1 = Vector.create([1])
// v2 :: Vector<_2, number>
const v2 = Vector.create([2, 3])
// v3 :: Vector<_3, number>
const v3 = v1.append(v2)
// v3.zip(v2) // error
console.log(v2.zip(v1.append(v1))) // Vector([[2,1],[3,1]])
ObjectDiff
operatorExample. A withDefaults
function (React)
import * as React from 'react'
import { ObjectOmit } from 'typelevel-ts'
export default function withDefaults<D, A extends D>(
C: React.ComponentType<A>,
defaults: D
): React.SFC<ObjectDiff<A, D>> {
return (props: any) => <C {...defaults} {...props} />
}
class Foo extends React.Component<{ bar: string; baz: number }, void> {}
const DefaultedFoo = withDefaults(Foo, { baz: 1 })
const x = <DefaultedFoo bar="bar" /> // ok
ObjectOmit
operatorExample. A withProps
function (React)
import { ObjectOmit } from 'typelevel-ts'
import * as React from 'react'
function withProps<D, P extends D>(C: React.ComponentType<P>, values: D): React.SFC<ObjectOmit<P, keyof D>> {
return (props: any) => <C {...props} {...values} />
}
class Foo extends React.Component<{ bar: string; baz: number }, void> {}
const FilledFoo = withProps(Foo, { baz: 1 })
const x = <FilledFoo bar="bar" /> // ok
How to return the intersection of the items
export type __THListIntersection<L extends THList, Acc> = {
true: Acc
false: __THListIntersection<THListTail<L>, THListHead<L> & Acc>
}[THListIsTHNil<L>]
/** returns the intersection of the contained types */
export type THListIntersection<L extends THList, WhenTHNil = never> = {
true: WhenTHNil
false: __THListIntersection<THListTail<L>, THListHead<L>>
}[THListIsTHNil<L>]
0.1.3
NumberToNat
NatToNumber
TupleToTHList
, THListToTuple
)FAQs
Type level programming in TypeScript
The npm package typelevel-ts receives a total of 6,990 weekly downloads. As such, typelevel-ts popularity was classified as popular.
We found that typelevel-ts 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.