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

Svelte 5: TS property type annotations are not fully erased #12685

Closed
brunnerh opened this issue Aug 1, 2024 · 3 comments
Closed

Svelte 5: TS property type annotations are not fully erased #12685

brunnerh opened this issue Aug 1, 2024 · 3 comments

Comments

@brunnerh
Copy link
Member

brunnerh commented Aug 1, 2024

Describe the bug

If a property is only typed and not assigned, it should be removed from output, otherwise there can be issues with shadowing.

Reproduction

<script lang="ts">
	class AutoAssign<T> {
			constructor(props: T) {
					Object.assign(this, props);
			}
	}

	class Test extends AutoAssign<Test> {
			id!: string; // remove this to make it work
	}

	const test = new Test({ id: 'test' });
	console.log('ID', test.id);
</script>

test: {JSON.stringify(test)}

REPL

Class after Svelte strips the types:

class Test extends AutoAssign {
	id; // remove this to make it work
}

In TS playground


(vitePreprocess and sveltePreprocess seem to remove the properties.)

Logs

No response

System Info

REPL

Severity

annoyance

@dummdidumm
Copy link
Member

I vaguely remember TS saying that this may be the right behavior because of how classes work now, and if you use some new option to downlevel classes differently it's the same output - but I could be mistaken

@brunnerh
Copy link
Member Author

brunnerh commented Aug 1, 2024

I tested changing the target/useDefineForClassFields and the behavior appears to conform to the configuration.
So I would call that user error (though those TS flags can be a bit tricky).

@brunnerh brunnerh closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants