Skip to content

adapt index.d.ts for end users #3582

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 2 commits into from
Sep 4, 2016
Merged

adapt index.d.ts for end users #3582

merged 2 commits into from
Sep 4, 2016

Conversation

HerringtonDarkholme
Copy link
Member

Related to #3509

TS declaration files need much hacks, as comments point out.
import Vue = require("vue") is the recommended way to import vue because it does not confuse TS/JS users whether to import default or import * as Vue and it does remind user the difference of commonjs module and es module.

@yyx990803
Copy link
Member

Would appreciate review from @ktsn @kaorun343

@kaorun343 kaorun343 mentioned this pull request Sep 2, 2016
@ktsn
Copy link
Member

ktsn commented Sep 2, 2016

LGTM 👍

@isotes
Copy link

isotes commented Sep 3, 2016

I was just trying out the new type definitions and had problems with importing them. I used the following alternative index.d.ts that worked for me in a Browserify environment before stumbling on this thread.:

export * from "./vue.d";
export * from "./options.d";
export * from "./plugin.d";
export * from "./vnode.d";
import {Vue} from "./vue.d";
export default Vue;

This supports several import styles and provides easy access to the other definitions besides Vue:

// just import Vue
import Vue from 'vue'
new Vue(...)

// import multiple definitions
import {Vue, ComponentOptions} from 'vue'

// import 'namespace style'
import * as Vuejs from 'vue'
new Vuejs.Vue(...)

What do you think?

@@ -1,2 +1,6 @@
import {Vue} from "./vue.d";
import {Vue as _Vue} from "./vue.d";

Choose a reason for hiding this comment

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

Why is this an import to ./vue.d? It should probably just be ./vue

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it should.

@kaorun343 would you please have a look on this? I don't want to solve two different issues in one pull request.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, I will fix this later.

@DanielRosenwasser
Copy link

@isotes The problem you're going to run into is that everyone represented CommonJS exports incorrectly, and so it's not clear what the "right" import style is going to be when the interop story is decided on. Right now, you can enable the default export behavior if you use the --allowSyntheticDefaultImports flag.

@isotes
Copy link

isotes commented Sep 4, 2016

@DanielRosenwasser Thanks for the clarification!

@yyx990803 yyx990803 merged commit 4061c42 into vuejs:next Sep 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants