New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-typesafe

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-typesafe

ESLint plugin to encourage type-safe practices

  • 0.5.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
271
decreased by-79.47%
Maintainers
1
Weekly downloads
 
Created
Source

Type-safe practices for TypeScript and JavaScript

Getting started

npm install --save-dev eslint-plugin-typesafe

And configure your .eslintrc file accordingly. For example:

{
    "plugins": [
        "typesafe",
    ],
    "rules": {
        "typesafe/no-throw-sync-func": "error",
        "typesafe/no-await-without-trycatch": "warn",
        "typesafe/promise-catch": "error",
    }
}

Motivation

TypeScript offers a power static typing system that can help developers to avoid painful bugs, especially in sizeable projects.

However, some limitations remain as TypeScript is committed to being a superset of the JavaScript language.

This plugin aims to implement additional rules that can help improve type safety, but are not available as standard ESLint rules.

For example, following functions have the same type signature:

function f(x: number): number {
    return x
}

function g(x: number): number {
    return Math.random() > 0.5 ? x : throw new Error()
}

There is also no way to force error handling:

function f(): never {
    throw new Error()
}

f() // No type error

Given a codebase of sufficient complexity, an unexpected error state will eventually occur that could bubble up to the entry point of the application.

Achieving maximal type safety

Instead of merely using TypeScript, consider encoding failures in your program with a library such as neverthrow, or adopting functional programming with fp-ts.

Existing rules

The current rule(s) are:

Future work

Integrate with typescript-eslint so that TypeScript syntax can be explicitly supported.

Keywords

FAQs

Package last updated on 20 Jan 2021

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