Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create branded, opaque, unique, single types? #150

Closed
millsp opened this issue Oct 6, 2020 · 0 comments
Closed

How to create branded, opaque, unique, single types? #150

millsp opened this issue Oct 6, 2020 · 0 comments
Labels
question More info is requested wiki It's nice to learn stuff

Comments

@millsp
Copy link
Owner

millsp commented Oct 6, 2020

馃 Question

Describe your question

Type branding is made possible by intersecting a type with a object type that has a non-existent property hidden behind a symbol type.

import {A} from 'ts-toolbelt'

type EUR = A.Type<number, 'eur'>
type USD = A.Type<number, 'usd'>

let eurWallet = 10 as EUR
let usdWallet = 15 as USD

eurWallet = usdWallet // error

Search tags, topics

nominal typing, branded types, opaque types, unique types

@millsp millsp added question More info is requested wiki It's nice to learn stuff labels Oct 6, 2020
@millsp millsp closed this as completed Oct 6, 2020
Repository owner locked and limited conversation to collaborators Feb 2, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question More info is requested wiki It's nice to learn stuff
Projects
None yet
Development

No branches or pull requests

1 participant