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

expect-type

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expect-type

[![CI](https://github.com/mmkal/expect-type/actions/workflows/ci.yml/badge.svg)](https://github.com/mmkal/expect-type/actions/workflows/ci.yml) ![npm](https://img.shields.io/npm/dt/expect-type) [![X (formerly Twitter) Follow](https://img.shields.io/twitte

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
781K
increased by629.57%
Maintainers
1
Weekly downloads
 
Created

What is expect-type?

The expect-type npm package is a TypeScript utility that allows developers to assert and validate types at compile time. It is particularly useful for ensuring that types are as expected during development, which can help catch type-related errors early.

What are expect-type's main functionalities?

Type Assertion

This feature allows you to assert that a given value matches a specific type. In this example, the `expectType` function is used to assert that the `user` object conforms to the `User` interface.

import { expectType } from 'expect-type';

interface User {
  name: string;
  age: number;
}

const user: User = { name: 'Alice', age: 30 };
expectType<User>(user);

Type Equality

This feature allows you to check if two types are equal. In this example, `expectType` is used to assert that types `A` and `B` are equal.

import { expectType } from 'expect-type';

type A = { a: string };
type B = { a: string };

expectType<A, B>(true);

Type Inference

This feature allows you to assert the inferred type of a value. In this example, `expectType` is used to assert that the result of the `add` function is a `number`.

import { expectType } from 'expect-type';

function add(a: number, b: number) {
  return a + b;
}

const result = add(1, 2);
expectType<number>(result);

Other packages similar to expect-type

Keywords

FAQs

Package last updated on 09 Oct 2024

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