Skip to content

Commit 3e194ce

Browse files
committed
fix: ignore as types expressions on property definitions
fixes #14179
1 parent aa23415 commit 3e194ce

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

.changeset/dull-laws-end.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ignore `as` types expressions on property definitions

packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ const visitors = {
5656
if (node.exportKind === 'type') return b.empty;
5757
return node;
5858
},
59-
PropertyDefinition(node) {
59+
PropertyDefinition(node, { next }) {
6060
if (node.accessor) {
6161
e.typescript_invalid_feature(
6262
node,
6363
'accessor fields (related TSC proposal is not stage 4 yet)'
6464
);
6565
}
66+
return next();
6667
},
6768
TSAsExpression(node, context) {
6869
return context.visit(node.expression);
@@ -97,7 +98,7 @@ const visitors = {
9798
if ((node.readonly || node.accessibility) && context.path.at(-2)?.kind === 'constructor') {
9899
e.typescript_invalid_feature(node, 'accessibility modifiers on constructor parameters');
99100
}
100-
return node.parameter;
101+
return context.visit(node.parameter);
101102
},
102103
FunctionExpression: remove_this_param,
103104
FunctionDeclaration: remove_this_param,

packages/svelte/tests/runtime-runes/samples/typescript/_config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { flushSync } from 'svelte';
22
import { test } from '../../test';
33

4+
// This test mainly checks that all types are properly ignored by the compiler
45
export default test({
56
html: '<button>clicks: 0</button>',
67

packages/svelte/tests/runtime-runes/samples/typescript/main.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
class Foo {
1212
public name: string;
13+
x = 'x' as const;
1314
constructor(name: string) {
1415
this.name = name;
1516
}

0 commit comments

Comments
 (0)