-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
[RFC436] interface delcared in setup function should be elevated to top scope instead of function scope #1966
Comments
😅temp solution,use |
it was answered here: #1964 (comment) You can define your type in a <script> (not setup), not very comfortable to have 2 scripts tag but it works <script lang="ts">
interface Test {
test: string
}
</script>
<script setup lang="ts" generic="T extends Test">
const props = defineProps<{
msg: T,
mmm: Test,
}>()
console.log(props.msg.test)
</script> |
This is expected behavior, consider following case we cannot move <script setup lang="ts">
let test = 'test';
interface Test {
test: typeof test
}
</script> |
So the solution here is using another script tag? It is more verbose than being optimal. Plus, it is not consistent with SFC's Consider this <script setup lang="ts">
import { ref } from 'vue'
interface Test {
test: string
}
const props = defineProps<Test>()
</script> will compile to this successfully. |
Yes, I mean elevate interface to top scope is not improvement, but it's a bug. This is an example, when interface in <script lang="ts">
const foo = 123;
</script>
<script lang="ts" setup>
const foo = 'foo';
interface Props {
foo: typeof foo; // string
}
defineProps<Props>()
</script> <script lang="ts">
const foo = 123;
interface Props {
foo: typeof foo; // number
}
</script>
<script lang="ts" setup>
const foo = 'foo';
defineProps<Props>()
</script> |
Input file:
Compiled virtual file
Note the interface should be compiled outside of render function.
The text was updated successfully, but these errors were encountered: