Skip to content

Add types #14

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

Merged
merged 8 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"contributors": [
"Titus Wormer <[email protected]> (https://wooorm.com)"
],
"types": "types/index.d.ts",
"files": [
"types/index.d.ts",
"index.js",
"factory.js",
"html.js",
Expand All @@ -41,7 +43,9 @@
"space-separated-tokens": "^1.0.0"
},
"devDependencies": {
"@types/hast": "^2.3.1",
Copy link
Member

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.

"browserify": "^16.0.0",
"dtslint": "^3.6.12",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"dtslint": "^3.6.12",
"dtslint": "^3.0.0",

"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark-cli": "^8.0.0",
Expand All @@ -59,7 +63,8 @@
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run generate && npm run format && npm run build && npm run test-coverage"
"test-types": "dtslint types",
"test": "npm run generate && npm run format && npm run build && npm run test-coverage && npm run test-types"
},
"nyc": {
"check-coverage": true,
Expand Down
11 changes: 11 additions & 0 deletions types/hastscript-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import h = require('hastscript')

h() // $ExpectType Element
h('.bar', {class: 'bar'}) // $ExpectType Element
h('.bar', 'child text') // $ExpectType Element
h('.bar', ['child text']) // $ExpectType Element
h('.foo', {class: 'bar'}, h('.baz')) // $ExpectType Element
h('.foo', {class: 'bar'}, [h('.baz')]) // $ExpectType Element
h('.bar',{class: 'bar'} , 'child text') // $ExpectType Element
h('.bar',{class: 'bar'}, ['child text']) // $ExpectType Element
h(false) // $ExpectError
18 changes: 18 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// TypeScript Version: 3.5

import {Element, Properties, Node} from 'hast'

/**
* DSL to create virtual hast trees for HTML or SVG
*
* @param selector Simple CSS selector
* @param properties Map of properties
* @param children (Lists of) child nodes
*/
declare function hastscript(
selector?: string,
properties?: Properties,
children?: string | Node | Array<string | Node>
): Element

export = hastscript
10 changes: 10 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"lib": ["es2015"],
"strict": true,
"baseUrl": ".",
"paths": {
"hastscript": ["index.d.ts"]
}
}
}
7 changes: 7 additions & 0 deletions types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"semicolon": false,
"whitespace": false
}
}