Skip to content

Commit

Permalink
fix: make defineProps work when reading a property from `defineProp…
Browse files Browse the repository at this point in the history
…s()` (#3633)

Co-authored-by: Johnson Chu <[email protected]>
  • Loading branch information
so1ve and johnsoncodehk authored Oct 8, 2023
1 parent b8fe220 commit 28013fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/vue-language-core/src/generators/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,11 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:

let setupCodeModifies: [() => void, number, number][] = [];
if (scriptSetupRanges.defineProps && !scriptSetupRanges.propsAssignName) {
if (scriptSetupRanges.withDefaults) {
setupCodeModifies.push([() => codes.push(`const __VLS_props = `), scriptSetupRanges.withDefaults.start, scriptSetupRanges.withDefaults.start]);
}
else {
setupCodeModifies.push([() => codes.push(`const __VLS_props = `), scriptSetupRanges.defineProps.start, scriptSetupRanges.defineProps.start]);
}
const ranges = scriptSetupRanges.withDefaults ?? scriptSetupRanges.defineProps;
codes.push(`const __VLS_props = `);
addVirtualCode('scriptSetup', ranges.start, ranges.end);
codes.push(`;\n`);
setupCodeModifies.push([() => codes.push(`__VLS_props`), ranges.start, ranges.end]);
}
if (scriptSetupRanges.defineSlots && !scriptSetupRanges.slotsAssignName) {
setupCodeModifies.push([() => codes.push(`const __VLS_slots = `), scriptSetupRanges.defineSlots.start, scriptSetupRanges.defineSlots.start]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts">
import { exactType } from 'vue-tsc/shared';
const foo = defineProps<{ foo: string }>().foo;
exactType(foo, '' as string);
</script>

0 comments on commit 28013fc

Please sign in to comment.