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

Typescript external support #88

Open
nicolas-zozol opened this issue Oct 13, 2017 · 6 comments
Open

Typescript external support #88

nicolas-zozol opened this issue Oct 13, 2017 · 6 comments
Assignees
Labels

Comments

@nicolas-zozol
Copy link
Collaborator

Writing a definition file embedded in the package, implementing the @types system: https://blog.angular-university.io/typescript-2-type-system-how-do-type-definitions-work-in-npm-when-to-use-types-and-why-what-are-compiler-opt-in-types/

@nicolas-zozol
Copy link
Collaborator Author

ParsecJ is a good source of inspiration for type definitions: https://github.com/jon-hanson/parsecj

@nicolas-zozol
Copy link
Collaborator Author

nicolas-zozol commented Oct 15, 2017

package.json must reference the typings:

"typings": "./masala.d.ts",

The problem is that typings is obsolete, so it could move quickly. Another option is that there is a convention so that, because package.json points on src/lib/index.js an entry point, then the @types system will search for src/lib/index.d.ts as definition file.

@nicolas-zozol
Copy link
Collaborator Author

Found it: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html

In package.json:

{
    "name": "@masala/parser",
    "main": "./src/build/index.js",
    "types": "./masala.d.ts"
}

@nicolas-zozol
Copy link
Collaborator Author

Good news, we can make solid overloading in type definitions with Typescript:

function reverse(string: string): string;
function reverse<T>(array: T[]): T[];

https://blog.mariusschulz.com/2016/08/18/function-overloads-in-typescript

@bd82
Copy link

bd82 commented Oct 19, 2017

Hello.

If you plan on developing the d.ts definitions APIs as part of this repository.
But keep this repository as a vanilla JS project.

There is a way to do so, while also ensuring that the APIs match the implemntation
using new TypeScript compiler options.

See: https://github.com/bd82/typescript_for_public_apis
For details on this suggested pattern.

@nicolas-zozol
Copy link
Collaborator Author

Yes, it will be a 100% pure JS lib, with a .d.ts available with @types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants