Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@arthurka/ts-utils

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arthurka/ts-utils

Some convenient TS utilities.

Source
npmnpm
Version
2.9.0
Version published
Maintainers
1
Created
Source

Usage

import { checkExactShape, ExactShape } from '@arthurka/ts-utils';

const tooFew = { first: 'Stefan' };
const exact = { first: 'Stefan', last: 'asd' };
const tooMany = { first: 'Stefan', last: 'asd', age: '37' };

const record: Record<string, string> = {};
type R = typeof record;
type Exact = typeof exact;
interface ExtendedRecord extends Exact, R {}
const extendedRecord: ExtendedRecord = {
  first: 'Stefan',
  last: 'asd',
  // asd: 'asd',
};

type Person = {
  first: string;
  last: string;
};


function savePerson<T>(person: ExactShape<T, Person>) {

}
savePerson(exact);
// @ts-expect-error
savePerson(tooFew);
// @ts-expect-error
savePerson(tooMany);
// @ts-expect-error
savePerson(record);
// @ts-expect-error
savePerson(extendedRecord);

function getPerson(): Person {
  const a = exact;
  // const a = tooFew;
  // const a = tooMany;
  // const a = record;
  // const a = extendedRecord;

  checkExactShape<Person>()(a);
  return a;
}

const person = getPerson();
console.info(person);

FAQs

Package last updated on 14 Jul 2022

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