-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Error: [@vue/compiler-sfc] Failed to resolve index type into finite keys #8286
Comments
@yyx990803 , can you check this issue? Looks like code was broken after refactoring. |
I ran into same issue if I do
|
downgrade to exact version: 3.2.47 will resolve this issue.. i've been faced same issue |
same problem |
The original repro (and any usage that used a It was an oversight in 3.2 - technically we should've just thrown errors in this case. But somehow many users considered this a "workaround" or accidentally relied on it without realizing it's being ignored for runtime codegen. However, this may be exactly what the user wants in certain scenarios, e.g. they just want a component to allow all HTML attrs at the type level, but treat them as fallthrough attrs. In 3.3, the compiler will now actually attempt to resolve the base type, and in this case the base type involves a complex type that is not supported, so it fails with an error. I've made this case to produce a more specific error message in 8235072 - the commit also allows you to explicitly ignore the extend (i.e. the 3.2 behavior) with an inline |
Hi @yyx990803, complex type includes also all the types which are created from type utility like |
It ANY type that have underline type-computations (even |
The magical comment is not a good DX friendly solution, IMHO |
There is a safe way (without |
This is a rather strange situation, it turns out that if you want to use basic html attributes on a component, you have to specify them all explicitly or use a hack with ignore comment. Given that we have attribute passing down, and we don't need to validate them, vue-tsc could suggest valid attributes for html elements by itself. This seems like a more elegant solution for a situation where we don't need to validate attributes in runtime. @yyx990803, сan you share your thoughts? |
If understand correctly this issue (which I also ran into) basically means that Vue 3 only supports "trivial" TypeScript types for props. In my opinion this in fact means that "Vue does not actually support TypeScript (but just a small subset of it)" - while the documentation misstates that it "provides first-class TypeScript support". Please either fix the issue or at least change the documentation to state that the TypeScript support is "limited" at best and not "first class" at all. |
In my personal view its so painfully. We have limited typescript and usual typescript together, in one place. This feels strange, unpredictable and boilerplaty, since we must declare app types and special types for half of components. Generating runtime checks from declarations was a bad idea, since its so limited. Its job that can be done on another side(api layer/business logic layer), even for simple cases. Also, its pretty useless, since (as i know) we cannot catch this runtime validation error and then change app behavior. |
agree, hope vue will fully support typescript in the future |
I agree with the comments above me. I recently ran into this issue when trying to extend from a global interface. You can find the code here: I personally think this case is rather common, where you have a global interface but a component needs to extend it because has additional properties that the base does not have. Adding |
As a workaround, component definition with <script lang="ts">
import { h } from 'vue';
export default defineComponent((props: ComplexType, context) => {
return () => h('div')
}, { props: ['prop1', 'prop2'] })
</script>
<!-- or -->
<script lang="tsx">
export default defineComponent((props: ComplexType, context) => {
return () => <div></div>
}, { props: ['prop1', 'prop2'] })
</script> |
Any news about this? |
Still need to be fixed... |
Vue doesn't aim to be a fully functional typescript resolver, so this issue will never be resolved since vue doesn't use typescript api, but a custom resolver based on babel AST. It only tries to resolve basic types we use (because creating a working type resolver requires a lot of work - see checker.ts!). If you rely on these complex types, I've created a new project: https://github.com/so1ve/unplugin-vue-complex-types which uses the typescript compiler's API to resolve these types. It's not finished yet, but stay tuned! :) Update: It has basic functionality now, but pretty slow! :( |
@vue-ignore is even pretty weird. interface Props extends /** @vue-ignore */ Extended { } its forced use case. I think there should be any other solution except vue-ignore. |
Vue version
3.3.1
Link to minimal reproduction
https://github.com/dimatakoy/vue-ts-bug
Steps to reproduce
Just use a common pattern that allows for convenient autocomplete code in SFC components
# Or just build repro example, you will see error in terminal. npm run build
What is expected?
works
What is actually happening?
System Info
Any additional comments?
looks like it works on 3.2.* and breaks after 3.3.*
The text was updated successfully, but these errors were encountered: