Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support placeholder and selectable-overloads #190

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 2 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# EditorConfig is awesome: http://EditorConfig.org

root = true

[*]
indent_size = 2
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
trim_trailing_whitespace = true
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
11 changes: 3 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
node_modules
dist
*.swp
*.swo
.session.vim
.sizecache.json
test.js
*.log
coverage/
node_modules/
ramda/
37 changes: 20 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
sudo: false
language: node_js

notifications:
email:
on_success: never
on_failure: never # change
node_js:
- stable

script:
- npm run lint
# - npm run bundle
- npm rm tslint
- npm install $TYPESCRIPT --force
# - npm run exec
- npm run test
- yarn run lint
- yarn run build-check
- yarn run remap-check
- yarn run test-utils -- --verbose --coverage
- yarn run test -- --verbose
- yarn run test-actual -- --verbose -u

env:
# - [email protected]
- TYPESCRIPT=typescript@latest
- TYPESCRIPT=typescript@next
after_success:
- if [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./scripts/deploy.sh; fi

node_js:
- "stable"
cache:
yarn: true
directories:
- node_modules

matrix:
fast_finish: true

notifications:
email: false
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Place your settings in this file to overwrite default and user settings.
{
"typescript.tsdk": "node_modules/typescript/lib"
"tslint.ignoreDefinitionFiles": false,
"tslint.exclude": "**/{node_modules,ramda}/**/*"
}
104 changes: 61 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,74 @@
## Type definitions for [Ramda](https://github.com/ramda/ramda)
# types/npm-ramda

[![Greenkeeper badge](https://badges.greenkeeper.io/types/npm-ramda.svg)](https://greenkeeper.io/)

[![Build Status](https://travis-ci.org/types/npm-ramda.svg?branch=master)](https://travis-ci.org/types/npm-ramda)
[![Travis](https://travis-ci.org/types/npm-ramda.svg?branch=master)](https://travis-ci.org/types/npm-ramda)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/donnut/typescript-ramda)
[![Greenkeeper](https://badges.greenkeeper.io/types/npm-ramda.svg)](https://greenkeeper.io/)

TypeScript's type definitions for [Ramda](https://github.com/ramda/ramda)

## Status

Typing compatible with ramda version 0.23.0.
Typing compatible with ramda version v0.24.1

***Note***: many of the functions in Ramda are still hard to properly type in Ramda, with issues mainly centered around partial application, currying, and composition, especially so in the presence of generics. And yes, those are probably why you'd be using Ramda in the first place, making these issues particularly problematic to type Ramda for TypeScript. A few links to issues at TS can be found [below](#Roadmap).

## Features

- support placeholder ( `R.__` )
- support partial import ( `import * as map from "ramda/src/map"` )
- support selectable overloads ( use 0-param: `R.map<"11", "list">()` )

## Usage

Install the typings for node using:
```bash
npm install types/npm-ramda --saveDev
The following command install the types from the `dist` branch, which is the newest version and contains `selectable` and `placeholder` types.

```sh
# using npm
npm install --save-dev ikatyang/types-ramda#dist

# using yarn
yarn add --dev ikatyang/types-ramda#dist
```

If you use the package through a script tag, install with the `--global` flag instead.

## Testing:
```
# check using `typings-checker` (recommended):
npm run types
## Testing

```sh
# build types (./templates/*.ts -> ./ramda/dist/**/*.d.ts)
yarn run build

# build types with watching mode
yarn run build-watch

# check if generated definitions are valid
yarn run build-check

# snapshot test for types
yarn run test

# compile errors only (doesn't prevent `any`, and can give false positives for bits that should error):
npm test
# without npm (useful on Windows):
node ./node_modules/typescript/bin/tsc --lib es2015 --module commonjs tests/test.ts --noEmit
# snapshot test for types with watching mode
yarn run test -- --watch

# test utils
yarn run test-utils

# actual test
yarn run test-actual

# NOTE: test files
# unit tests -> ./tests/*.ts
# actual tests -> ./tests/ramda-tests.ts
# integration tests -> ./tests/ramda-tests.ts

# remap snapshots (./tests/__snapshots__/*.ts.snap -> ./snapshots/*.ts)
yarn run remap

# remap snapshots with watching mode
yarn run remap-watch

# check if snapshot is outdated
yarn run remap-check
```

## FAQ
Expand All @@ -38,42 +79,19 @@ node ./node_modules/typescript/bin/tsc --lib es2015 --module commonjs tests/test
> Why does `compose` not infer well?
- TypeScript cannot do backward inference as needed for `compose` ([ref](https://github.com/Microsoft/TypeScript/issues/15680#issuecomment-307571917)). The `pipe` variants work a bit better than the `compose` versions.

## Note on placeholders
Due to incompatiblity problems with typescript's typing system, Ramda's placeholder
typing is removed. For binary functions the same functionally can be achieved using
`R.flip`. For example:

```typescript
// using a placeholder ...
R.subtract(R.__, 3);
// ... is the same as
R.flip(R.subtract)(3);
```

In Ramda almost all functions are curried. TypeScript does not natively support
currying, so in cases where we've omitted a combination this might break.
Example of a potential gap:
```typescript
R.insert(2, 'x', [1,2,3,4])
R.insert(2)('x', [1,2,3,4])
R.insert(2, 'x')([1,2,3,4])
R.insert(2)('x')([1,2,3,4]) // => type error!
```

## Contributing

Pull requests are welcome!
If you'd like to help out, two good places to start are the [issues](https://github.com/types/npm-ramda/issues)
as well as the [failed tests](https://github.com/types/npm-ramda/blob/master/tests/test.ts.out).
as well as the [tests](https://github.com/types/npm-ramda/blob/master/tests/ramda-tests.ts).

Do note that quite some of the typings are now being generated (manually) using the
[scripts](https://github.com/types/npm-ramda/blob/master/scripts.js),
as the typings are gradually getting out of hand to manually defined in the
[typings file](https://github.com/types/npm-ramda/blob/master/index.d.ts).
Do note that all of the typings are now being generated (automatically) using the
[tempaltes](https://github.com/types/npm-ramda/tree/master/templates#readme).

## Roadmap

High-level to-do to address recurring issues:

- `pipe` / `compose`:
- ~~using optional generics so as to allow annotating input parameter type(s)?~~
- [`gcnew/TypeScript#polyFuncUnification`](https://github.com/Microsoft/TypeScript/issues/9949#issuecomment-271926278)?
Expand Down
1 change: 1 addition & 0 deletions fixtures/build-check/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import * as R from '../../ramda/dist/index';
7 changes: 7 additions & 0 deletions fixtures/build-check/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"noEmit": true,
"skipLibCheck": false,
"typeRoots": []
}
}
Loading