Skip to content
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

SFC compiler breaks TypeScript when using <script> with <script setup> #5094

Closed
eliottrobson opened this issue Dec 11, 2021 · 0 comments
Closed

Comments

@eliottrobson
Copy link

eliottrobson commented Dec 11, 2021

Version

3.2.24

Reproduction link

sfc.vuejs.org/

Steps to reproduce

When using <script> with <script setup> the generated TypeScript code is different enough to break the TypeScript compiler. When only using setup the output can be correctly type checked. However, when using both, the output changes the output such that inferred types can no longer be inferred.

<template>
	<h1>{{ value }}</h1>
</template>

<script lang="ts">
export default {
	inheritAttrs: false
};
</script>

<script setup lang="ts">
import { computed } from 'vue';

const props = defineProps({
	test: {
		type: String,
		default: ''
	}
});
const value = computed(() => props.test);
</script>

Valid TypeScript output:
https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuXHQ8aDE+e3sgdmFsdWUgfX08L2gxPlxuPC90ZW1wbGF0ZT5cblxuPHNjcmlwdCBzZXR1cCBsYW5nPVwidHNcIj5cbmltcG9ydCB7IGNvbXB1dGVkIH0gZnJvbSAndnVlJztcblxuY29uc3QgcHJvcHMgPSBkZWZpbmVQcm9wcyh7XG5cdHRlc3Q6IHtcblx0XHR0eXBlOiBTdHJpbmcsXG5cdFx0ZGVmYXVsdDogJydcblx0fVxufSk7XG5jb25zdCB2YWx1ZSA9IGNvbXB1dGVkKCgpID0+IHByb3BzLnRlc3QpO1xuPC9zY3JpcHQ+IiwiaW1wb3J0LW1hcC5qc29uIjoie1xuICBcImltcG9ydHNcIjoge1xuICAgIFwidnVlXCI6IFwiaHR0cHM6Ly9zZmMudnVlanMub3JnL3Z1ZS5ydW50aW1lLmVzbS1icm93c2VyLmpzXCJcbiAgfVxufSJ9

Invalid TypeScript output:
https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuXHQ8aDE+e3sgdmFsdWUgfX08L2gxPlxuPC90ZW1wbGF0ZT5cblxuPHNjcmlwdCBsYW5nPVwidHNcIj5cbmV4cG9ydCBkZWZhdWx0IHtcblx0aW5oZXJpdEF0dHJzOiBmYWxzZVxufTtcbjwvc2NyaXB0PlxuXG48c2NyaXB0IHNldHVwIGxhbmc9XCJ0c1wiPlxuaW1wb3J0IHsgY29tcHV0ZWQgfSBmcm9tICd2dWUnO1xuXG5jb25zdCBwcm9wcyA9IGRlZmluZVByb3BzKHtcblx0dGVzdDoge1xuXHRcdHR5cGU6IFN0cmluZyxcblx0XHRkZWZhdWx0OiAnJ1xuXHR9XG59KTtcbmNvbnN0IHZhbHVlID0gY29tcHV0ZWQoKCkgPT4gcHJvcHMudGVzdCk7XG48L3NjcmlwdD4iLCJpbXBvcnQtbWFwLmpzb24iOiJ7XG4gIFwiaW1wb3J0c1wiOiB7XG4gICAgXCJ2dWVcIjogXCJodHRwczovL3NmYy52dWVqcy5vcmcvdnVlLnJ1bnRpbWUuZXNtLWJyb3dzZXIuanNcIlxuICB9XG59In0=

What is expected?

The output should be valid TypeScript for both types

What is actually happening?

TS7006: Parameter '__props' implicitly has an 'any' type.

// ...
function setup(__props) {

const props = __props
// ...

It looks like the types are inferred, and when the extra __default__ object is created the setup function is moved so it is defined outside the inferred usage scenario.

As far as I can tell, this started breaking from version 3.2.4 based on sfc.vuejs.org

@github-actions github-actions bot locked and limited conversation to collaborators Oct 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant