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
- Host: GitHub
- URL: https://github.com/danvk/ts-reftrans
- Owner: danvk
- License: apache-2.0
- Created: 2018-11-01T13:17:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-01T13:33:20.000Z (over 7 years ago)
- Last Synced: 2026-04-17T00:17:36.089Z (3 months ago)
- Language: TypeScript
- Size: 17.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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