-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Vue-tsc Compilation Error for Simple TS File #5091
Labels
question
Further information is requested
Comments
see #5089 (comment) I don't have access to edit the codesandbox but in your case this probably will fix import { ref, type Ref } from 'vue'
export function useResetRef<T>(initData: T) {
const data: Ref<T> = ref(initData)
return data
} |
I could reproduce too error. Reproductionpackage.json{
...(other properties)
"dependencies": {
"vue": "^3.5.13",
"vue-tsc": "^2.2.0"
}
} test.vue<script lang="ts">
import { ref } from 'vue'
export function useResetRef<T>(initData: T) {
const data = ref(initData)
return data
} cmdnpx vue-tsc --declaration --emitDeclarationOnly ./test.vue |
As mentioned above this is expected and it's how tsc works. ( you can call it limitation of typescript ) |
In this case specifically: // 1.
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
export function useResetRef<T>(initData: T) {
const data: [T] extends [Ref] ? IfAny<T, Ref<T>, T> : Ref<UnwrapRef<T>, UnwrapRef<T> | T> = ref(initData)
return data
}
// 2.
export function useResetRef<T>(initData: T) {
const data: Ref<T | undefined> = ref()
data.value = initData
return data
}
// 3.
export function useResetRef<T>(initData: T) {
const data = ref(initData) as Ref<T>
return data
}
// 4. Only work prior to vue 3.5 as the reactive system has refactored in 3.5
export function useResetRef<T>(initData: T) {
const data: Ref<UnwrapRef<T>> = ref(initData)
return data
} |
sorry, I missed read |
KazariEX
added
question
Further information is requested
and removed
pending triage
labels
Dec 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Vue - Official extension or vue-tsc version
2.2.0
VSCode version
1.96.0
Vue version
3.5.12
TypeScript version
5.6.2
System Info
No response
package.json dependencies
No response
Steps to reproduce
Declare a function and generate its type using vue-tsc
Execute the command vue-tsc-declaration-emitdeclarationonly at the console
What is expected?
Not throw an error and output a type file
What is actually happening?
src/hooks/useResetRef.ts:4:17 - error TS2742: The inferred type of 'useResetRef' cannot be named without a reference to '.pnpm/@VUE[email protected]/node_modules/@vue/shared'. This is likely not portable. A type annotation is necessary.
4 export function useResetRef(initData: T) {
~~~~~~~~~~~
Link to minimal reproduction
https://codesandbox.io/p/devbox/9kmzhk?file=%2Fsrc%2Fhooks%2Fuse-reset.ts%3A5%2C15
Any additional comments?
No response
The text was updated successfully, but these errors were encountered: