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

wip: data typing issue #200

Closed
wants to merge 1 commit into from
Closed

wip: data typing issue #200

wants to merge 1 commit into from

Conversation

lmiller1990
Copy link
Member

@lmiller1990 lmiller1990 commented Sep 10, 2020

This lets you use data with SFC imports as described in #194, but breaks the type safety for non SFCs. This seems unavoidable - I don't see how we can have the best of both words here, really.

I don't see a good solution for this in the short term, unless someone has figured a good way to extract type info from .vue files (not yet, or at least not stable yet).

Any ideas? Using vue files is much more common than using components defined with render functions, but I really value strong typing as well. I wonder if there is some way to not have as string type-checking for .vue files (using a shim). Eg: disable mounting option checks for shimmed vue files. I will do some research.

@cexbrayat @pikax would love some input.

Copy link
Member

@cexbrayat cexbrayat left a comment

Choose a reason for hiding this comment

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

I think @pikax may remember why we have never there, as he introduced it in 9af9de2 to help bump to beta.15. So he'll probably have a better insight.
If not, I'll need to take a deeper look. I'd love to keep the strong type safety if we can (as you suspect ;) )

@@ -1,6 +1,8 @@
import { expectError, expectType } from 'tsd'
import { defineComponent } from 'vue'
import { mount } from '../src'
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary? TBH I don't like @ts-ignore even less in dts tests where we're supposed to check that everything works :) I'd like this to work without it.

import Vue from 'vue'
export default any
const component: any
export default component
Copy link
Member

Choose a reason for hiding this comment

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

unrelated: Maybe we should use the same shim as the one provided by the CLI. It is not cast as any I know, but that would help catch errors that developers will encounter.

Copy link
Member

Choose a reason for hiding this comment

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

I think Component is a better candidate, but needs testing

Copy link
Member Author

Choose a reason for hiding this comment

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

From what I can tell since the shim gives you no information about your component (eg props/data/whatever) the majority of the types we have are not very useful. in my experience the vast majority of people are using vue files.

I think we are focusing too heavily on "correct typing" and not enough on the actual DX. At least from my point of view, I would rather not have type safety than have random ts compile errors even doing the most basic of things (like using data).

I wonder if there is some way to ignore all the mounting types when the imported component is from a vue file? That would really be ideal, at least at this point, since you cannot get any useful information from an SFC right now.

Copy link
Member

Choose a reason for hiding this comment

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

without a typescript plugin that will handle vue files, I doubt we can extract much information from a .vue file.

The shim only tells the typescript: "this file import is of this type" - without any process.

Copy link
Member Author

@lmiller1990 lmiller1990 Sep 10, 2020

Choose a reason for hiding this comment

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

I think we need to merge something (this or something better?) sooner rather that later... using data to set a component up for testing is basically the Hello World of VTU and it doesn't work out of the box atm. I do not want to ruin the hard work that has gone into typing VTU, though, with ts-ignore and any etc... 🤔

@lmiller1990 lmiller1990 deleted the fix-data-option branch September 17, 2020 11:38
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.

None yet

3 participants