-
Notifications
You must be signed in to change notification settings - Fork 235
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
declare module '*.vue' { | ||
// TODO: Figure out the typing for this | ||
import Vue from 'vue' | ||
export default any | ||
const component: any | ||
export default component | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { expectError, expectType } from 'tsd' | ||
import { defineComponent } from 'vue' | ||
import { mount } from '../src' | ||
// @ts-ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary? TBH I don't like |
||
import Hello from '../tests/components/Hello.vue' | ||
|
||
const AppWithDefine = defineComponent({ | ||
props: { | ||
|
@@ -20,17 +22,6 @@ expectType<string>( | |
}).vm.a | ||
) | ||
|
||
// no data provided | ||
expectError( | ||
mount(AppWithDefine, { | ||
data() { | ||
return { | ||
myVal: 1 | ||
} | ||
} | ||
}) | ||
) | ||
|
||
// can not receive extra props | ||
expectError( | ||
mount(AppWithDefine, { | ||
|
@@ -153,3 +144,12 @@ mount(AppWithProps, { | |
} | ||
} | ||
}) | ||
|
||
// SFC with data option | ||
mount(Hello, { | ||
data() { | ||
return { | ||
foo: 'bar' | ||
} | ||
} | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.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 think
Component
is a better candidate, but needs testingThere 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.
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.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.
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.
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 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... 🤔