New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

flow-newtype

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flow-newtype

Flow implementation of newtype

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

flow-newtype

Flow implementation of NewType

Install

$ npm install flow-newtype
# or
$ yarn add flow-newtype

Usage

We can easily give new names to an existing types by extending the NewType class.

For example, we can create a Url type which simply wraps strings:

import { NewType } from 'flow-newtype'

// Define the `Url` type
class Url extends NewType<string> {}

// Create instances using the `new` operator
const googleUrl = new Url(`https://google.com/`)

// Or with `of`, which is provided as a static method
const githubUrl = Url.of(`https://github.com/`)

Now we can use the type in annotations:

// Require `Url` values instead of just a plain `string`
function fetchUrl(url: Url): Promise<Response> {

  // Unwrap the value using the `unwrap` instance method
  const urlString = url.unwrap()

  // Do stuff with `urlString`
}

FAQs

Package last updated on 22 Jul 2017

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