๐Ÿ’Ž Polish for the rough parts of TypeScript

Overview

Emery

๐Ÿ’Ž Polish for the rough parts of TypeScript.

TypeScript is great but there's parts that are still rough around the edges, especially for developers who are new to the language.

Purpose and intent

Emery is a small collection of utilities that improve DX without compromising static types.

Check for ambiguous types

Emery exposes "checks" for dealing with ambiguous types.

Checks are just predicates that can't be expressed as type guards, without enforcing opaque types.

import { checkAll, isNonNegative, isInteger } from 'emery';

/**
 * Along with some default check functions, we provide helpers
 * for managing combinations. The `checkAll` helper is a bit
 * like `pipe` for predicates.
 */
export const isNonNegativeInteger = checkAll(isNonNegative, isInteger);

Assert the validity of props

An assertion declares that a condition be true before executing subsequent code, ensuring that whatever condition is checked must be true for the remainder of the containing scope.

import { assert } from 'emery';

import { isNonNegativeInteger } from './path-to/check';

function getThingByIndex(index: number) {
  assert(isNonNegativeInteger(index));

  return things[index]; // ๐ŸŽ‰ Safely use the `index` argument!
}

Smooth over loose types

Utility functions for smoothing over areas of TypeScript that are loosely typed.

Because of JavaScript's dynamic implementation the default TS behaviour is correct, but can be frustrating in certain situations.

import { typedKeys } from 'emery';

const obj = { foo: 1, bar: 2 };

const thing = Object.keys(obj).map(key => {
  return obj[key]; // ๐Ÿšจ 'string' can't be used to index...
});
const thing2 = typedKeys(obj).map(key => {
  return obj[key]; // ๐ŸŽ‰ No more TypeScript issues!
});

Philosophy and motivation

Like all good things, Emery started with curiosity. At Thinkmill we have an internal Slack channel for TypeScript where a question was raised about how to offer consumers error messages that convey intent, not just cascading type failures.

While that's not currently possible, it became apparent that there was demand for a solution. We also discovered that many developers were carrying around miscellaneous utilities for working with TypeScript between projects.

Comments
  • Version Packages

    Version Packages

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Patch Changes

    opened by github-actions[bot] 1
  • Version Packages

    Version Packages

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Minor Changes

    opened by github-actions[bot] 1
  • Version Packages

    Version Packages

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Minor Changes

    opened by github-actions[bot] 1
  • Version Packages

    Version Packages

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Patch Changes

    • #30 f3bed0d Thanks @jossmac! - Loosely type object util args.

      If folks had strongly typed objects, they wouldn't need these utils. Support any object to save some headaches. Affects:

      • typedEntries()
      • typedKeys()
    opened by github-actions[bot] 1
  • Version Packages

    Version Packages

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Patch Changes

    opened by github-actions[bot] 1
  • Version Packages

    Version Packages

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Minor Changes

    opened by github-actions[bot] 1
  • Homepage tweaks

    Homepage tweaks

    Just a couple of language tweaks to the homepage, I wanted to try for a simpler / to the point heading, and explain why a bit sooner.

    Also the origin story page does a great job of explaining things (could really be the homepage tbh) so I wanted to surface a link to that as well.

    opened by JedWatson 1
  • [idea] Default messages

    [idea] Default messages

    It might be nice for internal predicates to expose default messages. Maybe we could attach some property to the function?

    isNonNegativeInteger.errorMessage = 'Must be a non-negative integer'
    

    When used lazily, that might look like:

    typeInvariant(isNonNegativeInteger, index) // 'Must be a non-negative integer'
    

    While still supporting custom messages:

    typeInvariant(isNonNegativeInteger(index), 'someFunction expects "index" to be a non-negative integer')
    
    enhancement 
    opened by jossmac 1
  • Subdued assertion

    Subdued assertion

    Discussed in https://github.com/Thinkmill/emery/discussions/33

    Originally posted by jossmac July 7, 2022 Sometimes I want to warn consumers about potentially invalid behaviour without actually throwing an error

    opened by jossmac 0
  • Simplify and refine where possible

    Simplify and refine where possible

    Opaques changes:

    • remove docs and exports for Transparent type generic (still used internally)
    • remove toTransparent util
    • rename ~toOpaque~ to castToOpaque
    • recommend unique symbols for stronger types

    Misc. changes:

    • Only support boolean condition against assert()
    • Fix weird edge case with isDefined()
    • Docs tidy

    | Assert changes | Opaque changes | | ------------- | ------------- | | assert changes | image |

    opened by jossmac 0
  • Dir structure

    Dir structure

    Directory restructure + docs alignment:

    • creature "utils" directory
      • move error utils
      • move object utils
    • move "runtime" stuff to utils file under "checks" directory
    opened by jossmac 0
Releases(v1.4.1)
App for displaying geospatial data on queues on the Polish-Ukrainian border.

Live app embedded here. App helps coordinate volunteer work with refugees from Ukraine on Polish-Belarusian Border. Data comes from Grupa Granica โ€“ a

null 3 Mar 10, 2022
Map of reception points for refugees near Polish-Ukrainian border

ua-2022-map Map of reception points for refugees near Polish-Ukrainian border work in progress... Development We provide a docker-based dev environmen

OpenStreetMap Polska 39 Dec 7, 2022
Hemsida fรถr personer i Sverige som kan och vill erbjuda boende till mรคnniskor pรฅ flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo fรถr kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
aka Scaletor, take screenshots of a piece of a map and scale/compare with other parts of the map

scale-a-tron A quick-and-dirty map that lets you compare one area to another. Draw a shape around a region, zoom in to another place on the map, and c

Stamen Design 24 Nov 7, 2022
๐Ÿ GitHub action to split your Git release tag into SemVer 2.0 parts

?? Git Tag Action GitHub action to split your Git release tag into SemVer 2.0 parts This is a simple action to split your git tag, usually for release

Noel 5 Oct 31, 2022
The awesomebooks project is a simple list, but separated into 3 parts and given a retro feel. The main page is where we can add books, and on another page we can see the list, and remove items. There is also a "contact-us" page.

Awesome Books This is the restructured version of the famous awesome-books project! Here you can find JavaScript broken into modules, using import-exp

Matt Gombos 12 Nov 15, 2022
:books: The definitive guide to TypeScript and possibly the best TypeScript book :book:. Free and Open Source ๐ŸŒน

TypeScript Deep Dive I've been looking at the issues that turn up commonly when people start using TypeScript. This is based on the lessons from Stack

Basarat Ali Syed 18.7k Jan 4, 2023
Variant types in Roblox TypeScript - Ported from Vanilla TypeScript

Variant (for Roblox) This is a roblox typescript variant (heh, pun) of Variant. See the Variant documentation on how to use Variant. A variant type is

Australis 2 Jun 3, 2022
A Lua plugin, written in TypeScript, to write TypeScript (Lua optional).

typescript.nvim A minimal typescript-language-server integration plugin to set up the language server via nvim-lspconfig and add commands for convenie

Jose Alvarez 315 Dec 29, 2022
typescript-to-jsonschema generates JSON Schema files from your Typescript sources.

fast-typescript-to-jsonschema English | ็ฎ€ไฝ“ไธญๆ–‡ a tool generate json schema from typescript. Feature compile Typescript to get all type information conve

yunfly 21 Nov 28, 2022
Convert some JavaScript/TypeScript code string into a .d.ts TypeScript Declaration code string

convert-to-dts Converts the source code for any .js or .ts file into the equivalent .d.ts code TypeScript would generate. Usage import { convertToDecl

Lily Scott 11 Mar 3, 2022
Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript.

Screeps Typescript Starter Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript. It provides everything you need to s

null 3 Jan 27, 2022
Movehat is a TypeScript SDK for Move on Sui built on top of Sui's TypeScript SDK and our fork of Ian Macalinao's `move-ts`.

Movehat Movehat is a TypeScript SDK for Move on Sui built on top of Sui's TypeScript SDK and our fork of Ian Macalinao's move-ts. Movehat aspires to b

Pentagon 10 Sep 30, 2022
๐Ÿฌ A simplified implementation of TypeScript's type system written in TypeScript's type system

?? HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Ronen Amiel 1.8k Dec 20, 2022
A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

CTSP- Create TS Project A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and conf

Jean Rodrรญguez 7 Sep 13, 2022
This project is a boilerplate for Next and TypeScript projects. This template was built with Vite, TypeScript and Stitches.

Awesome Template Stitches โ€” NextJS, TypeScript, Stitches and Design Tokens Summary About this template Avaliale scripts Other scripts available Main t

Diego Silva 14 Dec 29, 2022
TypeScript CLI for creating HTML & CSS & TypeScript project with different bundlers, v2022.10.23 is ready on NPM

TSCI CLI TypeScript CLI for creating HTML & CSS & TypeScript project with different bundlers. Installation npm i -g tsci Usage Want to contribute? You

Samet ร‡ELฤฐKBIร‡AK 7 Dec 14, 2022
A new Node.js resource built using Gatsby.js with React.js, TypeScript, and Remark.

Nodejs.dev Nodejs.dev site built using Gatsby.js with React.js, TypeScript, SCSS, and Remark. You can find the latest Figma design protype here. ?? Ge

Node.js 2.2k Jan 5, 2023