{"_id":"rtype","_rev":"3-0f627590557d8646867de531c062d954","name":"rtype","description":"Intuitive type notation for JavaScript.","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"rtype","version":"1.0.0","description":"Intuitive type notation for JavaScript.","main":"index.js","directories":{"doc":"docs"},"scripts":{"test":"babel-node test/index.js"},"repository":{"type":"git","url":"git+https://github.com/ericelliott/rtype.git"},"keywords":["type","types","type","annotation","annotation"],"author":{"name":"Eric Elliott"},"license":"MIT","bugs":{"url":"https://github.com/ericelliott/rtype/issues"},"homepage":"https://github.com/ericelliott/rtype#readme","gitHead":"e34f973202f7e9d85aefdf5134973e626d922d00","_id":"rtype@1.0.0","_shasum":"13928153f80367b4274aca93e55cc3755ffe0113","_from":".","_npmVersion":"2.14.4","_nodeVersion":"4.1.1","_npmUser":{"name":"ericelliott","email":"eric@ericleads.com"},"dist":{"shasum":"13928153f80367b4274aca93e55cc3755ffe0113","tarball":"https://registry.npmjs.org/rtype/-/rtype-1.0.0.tgz","integrity":"sha512-WSsSzaEXB1UiVLV6VyIkY5kXuc0YzgffVnlkrSRDDFbED63z3OJLhiQmFXiZm8Ne+ZUxO4C4K7bwxlN94tka2w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDJxXvhz2QOG3Hcng9k0JASz+q34eFY1dETznu5Qmm4sQIhAK+DPbKiKhN77md0H9TRJCf3SdI0NQNqR5hmaSDOaaOc"}]},"maintainers":[{"name":"ericelliott","email":"eric@ericleads.com"}]}},"readme":"# rtype\n\nIntuitive type notation for JavaScript.\n\n## About rtype\n\n* Compiler-free type notation.\n* Standing on the shoulders of giants: ES6, TypeScript, Haskell, Flow, & React\n\n\n## Status\n\nDeveloper preview. Breaking changes expected.\n\n\n## Why?\n\nPerhaps the most important part of API documentation is to quickly grasp the function signatures and data structures required to work with the API. There are existing standards for this stuff, but I don't like them, for various reasons.\n\n* JSDoc is too verbose, not intuitive, and painful to maintain.\n* TypeScript's structural types are very appealing, but currently somewhat difficult to integrate into workflows that don't have explicit support for it.\n\nI want a type syntax that is very clear to modern JavaScript developers (ES2015+), that could potentially be used at runtime with simple utilities.\n\n\n## What is an rtype?\n\nAn rtype is a string that represents the type of a variable in JavaScript.\n\n\n## Reading Function Signatures\n\nFunction types are described by a **function signature**. The function signature tells you each parameter and its type, separated by a colon, and the corresponding return type:\n\n```js\n(param: type): returnType\n```\n\nTo make the signature familiar to readers, we use common JavaScript idioms such as destructuring, defaults, and rest parameters:\n\n```js\n({ count = 0: number }): any\n(...args: string): any\n(firstIndex[]): any\n```\n\n### Optional Parameters\n\nOptional parameters can be indicated with `?`:\n\n```js\nUser({ name: string, avatarUrl? }): User\n```\n\n### Array Types\n\nArrays with typed contents can be represented like this:\n\n```js\nnumber[]\n```\n\n### The `any` Type\n\nThe special type `any` means that any type is allowed:\n\n```js\n(...args: any): array\n```\n\n\n### Union Types\n\nUnion types are denoted with the OR operator, `||`:\n\n```js\n(userInput: string || number): string || number;\n```\n\n### Builtin Types\n\n```js\nboolean, number, string, array, object, func\n```\n\nHere, `func` stands in for `function` because `function` is a reserved word.\n\nYou can instead describe a function's signature using a function `interface`:\n\n```js\nUser({ name: string, avatarUrl? }): user\n```\n\nYou can also use the generic `interface` syntax:\n\n```js\ninterface User {\n  ({ name: string,  avatarUrl? }): User\n}\n```\n\n\n### Interface: User Defined Types\n\nYou can create your own types using `interface`:\n\n```js\nUser, Record, Avatar, Cart\n```\n\nAn interface spells out the structure of the object:\n\n```js\ninterface user {\n  name: string,\n  avatarUrl?: url,\n  about?: string\n}\n```\n\nBy default, all values are required.\n\n\nThere's a shorthand for type literal forms:\n\n```js\ninterface user {\n  name: /\\w+/,\n  description?: ''\n  likes?: [],\n  data?: {}\n}\n```\n\nA one-line interface doesn't need brackets:\n\n```js\ninterface name: /\\w+/\n```\n\nAnd arrow functions:\n\n```js\ninterface stamp (obj) => {\n  return typeof obj === 'function' &&\n    typeof obj.compose === 'function';\n}\n```\n\nLooking into the future, all of this could eventually be specified inline in ES6 with no compile step:\n\n```js\nimport rtype from 'rtype';\n\nconst isStamp = (obj) => {\n  return typeof obj === 'function' &&\n    typeof obj.compose === 'function';\n};\n\nconst Stamp = rtype`interface stamp ${ isStamp }`;\n```\n\n## References\n\nSomewhat related ideas and inspiration sources.\n\n* [TypeScript](http://www.typescriptlang.org/)\n* [Flow](http://flowtype.org/)\n* [Typed Objects](http://wiki.ecmascript.org/doku.php?id=harmony:typed_objects)\n","maintainers":[{"name":"ericelliott","email":"eric@ericleads.com"}],"time":{"modified":"2022-06-26T14:40:55.933Z","created":"2015-10-04T01:19:15.961Z","1.0.0":"2015-10-04T01:19:15.961Z"},"homepage":"https://github.com/ericelliott/rtype#readme","keywords":["type","types","type","annotation","annotation"],"repository":{"type":"git","url":"git+https://github.com/ericelliott/rtype.git"},"author":{"name":"Eric Elliott"},"bugs":{"url":"https://github.com/ericelliott/rtype/issues"},"license":"MIT","readmeFilename":"README.md"}