Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tsargs

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsargs

typescript function arguments utils

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NPM Version

tsargs

TypeScript utility types for function arguments

  • Pick type of specific argument
  • Prepend arguments
  • Append arguments

Tested with static asserts

Should use typescript 2.8 and upper

Install & use

npm i tsargs
import { Arg2 } from 'tsargs';

function foo(a: number, b: string) {}

const secondArg: Arg2<typeof foo> = 'hello world!';

Pick argument

Use ArgN type to pick N argument (max 10 arg)

import { Arg2 } from 'tsargs';

function foo(a: number, b: string) {}

const secondArg: Arg2<typeof foo> = 'hello world!';

Prepend arguments

Useful for typed callbacks, rpc or event

Use PreNArgJ type to prepend N arguments to function with J arguments (max 10 arg)
or PreNArgN type to prepend N arguments to function with unknown arguments number

import { Pre1Arg2, Pre1ArgN } from 'tsargs';

function foo(a: number, b: string) {}
function boo(x: string, a: number, b: string) {}

const booFromFoo: Pre1Arg2<string, typeof foo> = boo;
const booFromFoo2: Pre1ArgN<string, typeof foo> = boo;

PreNArgN type may cause low ts performance

Append arguments

Useful for typed callbacks, rpc or event

Use PostNArgJ type to append N arguments to function with J arguments (max 10 arg)
or PostNArgN type to append N arguments to function with unknown arguments number

import { Post1Arg2, Post1ArgN } from 'tsargs';

function foo(a: number, b: string) {}
function boo(a: number, b: string, x: string) {}

const booFromFoo: Post1Arg2<string, typeof foo> = boo;
const booFromFoo2: Post1ArgN<string, typeof foo> = boo;

PostNArgN type may cause low ts performance

Pick range of arguments

Callbacks & arguments list

Use Args10 to pick 10 args of function

Use ArgsNoffOffset to pick N args with Offset offset (max 10 arg)

import { Args2off1 } from 'tsargs';

function foo(a: boolean, b: number, c: string) {}
const argsBC: Args2off1<typeof foo> = [ 123, 'Hello' ];

Roadmap

  • Example of typed event emitter
  • ✔ Pick range of arguments to array type
  • Pick any number of arguments to array type
  • Pick arguments to object
  • Specific argument's type replace
  • Remove arguments
  • Replace return type (not yet possible with buggy ts 3.0.3 rest parameters)

Write issue on github if you have any trouble with arguments in typescript

Keywords

FAQs

Package last updated on 02 Sep 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc