Skip to content

feat: TypeScript support #43

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 5 commits into from
Jan 16, 2019
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"test": "jest",
"lint": "eslint src",
"build": "rollup -c",
"prepare": "rollup -c"
"prepare": "rollup -c",
"test:types": "tsc -p ./types/tsconfig.json"
},
"repository": {
"type": "git",
Expand All @@ -35,6 +36,7 @@
"lint-staged": "^6.1.0",
"puppeteer": "^1.0.0",
"rollup": "^0.55.3",
"typescript": "^3.2.2",
"vue": "^2.5.13",
"yorkie": "^1.0.3"
},
Expand Down
8 changes: 8 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as VueJS from 'vue'
Copy link
Member

Choose a reason for hiding this comment

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

To adjust to the type definitions of other libraries, I think that we should be directly import rather than as using.

import _Vue from 'vue'

ref: vuex https://github.com/vuejs/vuex/blob/dev/types/index.d.ts#L1


declare function wrap(
Vue: VueJS.default,
Copy link
Member

Choose a reason for hiding this comment

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

From the above, I think that it will be below using typeof.

  Vue: typeof _Vue

Component: VueJS.VueConstructor<VueJS.default>
Copy link
Member

Choose a reason for hiding this comment

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

Considering the asynchronous component, i think we should be defined the below.

  ComponentOptions<Vue> | typeof Vue | AsyncComponent

ref: vue-router
https://github.com/vuejs/vue-router/blob/dev/types/router.d.ts#L3

Copy link
Member

Choose a reason for hiding this comment

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

Component | AsyncComponent may be better, I guess. It includes functional component and the type parameter of ComponentOption is never which makes it the top type in type parameters variation as the type param is contravariant.

): HTMLElement

export default wrap
13 changes: 13 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"strict": true,
"noEmit": true,
"lib": [
"es2015",
"dom"
]
},
"include": [
"./*.ts"
]
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3390,6 +3390,11 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@^3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5"
integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==

uglify-js@^2.6:
version "2.8.29"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd"
Expand Down