An open API service indexing awesome lists of open source software.

https://github.com/danvk/ts-reftrans

Demonstration of issues around referential transparency and type inference in TypeScript
https://github.com/danvk/ts-reftrans

Last synced: about 1 month ago
JSON representation

Demonstration of issues around referential transparency and type inference in TypeScript

Awesome Lists containing this project

README

          

# Referential Transparency and TypeScript

This repo contains [code samples](src/) from a talk I gave at [TSNYC 3.1.1][meetup].

To view the samples yourself in vscode, run:

git clone https://github.com/danvk/ts-reftrans.git
cd ts-reftrans
yarn
code .

For more of a writeup, see [this issue][issue] on the TypeScript repo.

The improvement on `Partial` that I presented is a variant on some code from
[this question][trick] on Stack Overflow. It's like `Pick` but infers the keys
that you want to pick:

```ts
const inferringPick = () => (x: Pick): Pick => x;

// v's type is inferred as Pick
const v = inferPick()({
method: 'GET',
cache: 'no-cache',
body: 'hello world'
});
```

[meetup]: https://www.meetup.com/TypeScriptNYC/events/255170060/
[issue]: https://github.com/Microsoft/TypeScript/issues/27502
[trick]: https://stackoverflow.com/a/46101222/388951