-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add types #14
Add types #14
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @TaylorBeeston! 🙇
@ChristianMurphy Any thoughts on the |
Thanks for drawing my attention to that, I missed it the first read through.
We may need to refactor this to flatten the typings out to the top level to support this. |
Co-authored-by: Christian Murphy <[email protected]>
Co-authored-by: Christian Murphy <[email protected]>
I wonder if we can get around this by changing the |
I'm not sure if this is the best way to do it or not as I'm still a little new to working with Github, but I have pushed the commit |
package.json
Outdated
@@ -41,7 +44,9 @@ | |||
"space-separated-tokens": "^1.0.0" | |||
}, | |||
"devDependencies": { | |||
"@types/hast": "^2.3.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we’re putting dependent types in dependencies
directly now, not in dev-deps.
package.json
Outdated
"browserify": "^16.0.0", | ||
"dtslint": "^3.6.12", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"dtslint": "^3.6.12", | |
"dtslint": "^3.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the path trick in tsconfig is working, here's how to test.
inside hastscript
npm install
npm link .
outside hastscript create a new folder with
index.ts
import s = require("hastscript/svg")
s("path")
and tsconfig.json
{
"compilerOptions": {
"lib": ["es2015"],
"strict": true,
"baseUrl": "."
}
}
in the new folder run
npm link hastscript
then test by running
npx -p typescript -p ts-node ts-node index.ts
(or running ts-node index.ts
directly if you have it installed globally)
Currently I'm getting
Could not find a declaration file for module 'hastscript/svg'. '~/test/node_modules/hastscript/svg.js' implicitly has an 'any' type.
Try `npm install @types/hastscript` if it exists or add a new declaration (.d.ts) file containing `declare module 'hastscript/svg';`
1 import s = require("hastscript/svg")
~~~~~~~~~~~~~~~~
@ChristianMurphy gotcha. Thanks for explaining how to test this! I hadn't thought to use |
Flattening the types then seems the most reasonable? |
Agreed, it's what we've done for other packages that have multiple files that need typings, like https://github.com/syntax-tree/unist-util-is |
I have just pushed out three commits, two of them are the suggestions by @wooorm above regarding By the way, unist-util-is has @types/mdast listed as a dev dependency, just so you know |
That is intentional, it is only used in the tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @TaylorBeeston! 🙇
Sweet, thanks Taylor! Released! |
Closes GH-13
.This PR adds the
types
directory that contains anindex.d.ts
file that allows TypeScript projects to use this package more easily. Additionally, there are some tests to ensure the correctness of this type definition, and some boilerplate associated withdtslint
.package.json
has been updated to include@types/hast
anddtslint
as dev dependencies. There is also the addition of the test-types script to run dslint, and index.d.ts is exported as the types file for this project.This is my second time writing a .d.ts file for a project, so please forgive me if there are any issues. One thing I would like to note is that I'm not 100% how this will work with
s
instead ofh
. I'm fairly certain that it will get the same type definition, which should be flexible enough to work with both functions, but I have been having a hard time finding this information out for certain.