Skip to content

Commit 2394f19

Browse files
authored
fix: don't hide $props's type argument error (#3126)
#3124. Remove the old type-argument handling, it was only in early beta that this was viable
1 parent e549d19 commit 2394f19

3 files changed

Lines changed: 21 additions & 16 deletions

File tree

‎.changeset/tall-doors-yawn.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte2tsx': patch
3+
---
4+
5+
fix: don't hide $props type argument error

‎packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,30 +207,30 @@ export class ExportedNames {
207207
}
208208

209209
// Easy mode: User uses TypeScript and typed the $props() rune
210-
if (node.initializer.typeArguments?.length > 0 || node.type) {
210+
if (node.type) {
211211
this.hoistableInterfaces.analyze$propsRune(node);
212212

213-
const generic_arg = node.initializer.typeArguments?.[0] || node.type;
214-
const generic = generic_arg.getText();
215-
if (ts.isTypeReferenceNode(generic_arg)) {
216-
this.$props.type = generic;
213+
const props_type = node.type;
214+
const type_name = props_type.getText();
215+
if (ts.isTypeReferenceNode(props_type)) {
216+
this.$props.type = type_name;
217217
} else {
218218
// Create a virtual type alias for the unnamed generic and reuse it for the props return type
219219
// so that rename, find references etc works seamlessly across components
220220
this.$props.type = '$$ComponentProps';
221221
preprendStr(
222222
this.str,
223-
generic_arg.pos + this.astOffset,
223+
props_type.pos + this.astOffset,
224224
`;type ${this.$props.type} = `
225225
);
226-
this.str.appendLeft(generic_arg.end + this.astOffset, ';');
226+
this.str.appendLeft(props_type.end + this.astOffset, ';');
227227
this.str.move(
228-
generic_arg.pos + this.astOffset,
229-
generic_arg.end + this.astOffset,
228+
props_type.pos + this.astOffset,
229+
props_type.end + this.astOffset,
230230
node.parent.pos + this.astOffset
231231
);
232232
this.str.appendRight(
233-
generic_arg.end + this.astOffset,
233+
props_type.end + this.astOffset,
234234
// so that semantic tokens ignore it, preventing an overlap of tokens
235235
surroundWithIgnoreComments(this.$props.type)
236236
);

‎packages/svelte2tsx/src/svelte2tsx/nodes/HoistableInterfaces.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ export class HoistableInterfaces {
275275
initializer: ts.CallExpression & { expression: ts.Identifier };
276276
}
277277
) {
278-
if (node.initializer.typeArguments?.length > 0 || node.type) {
279-
const generic_arg = node.initializer.typeArguments?.[0] || node.type;
280-
if (ts.isTypeReferenceNode(generic_arg)) {
281-
const name = this.getEntityNameRoot(generic_arg.typeName);
278+
if (node.type) {
279+
const props_type = node.type;
280+
if (ts.isTypeReferenceNode(props_type)) {
281+
const name = this.getEntityNameRoot(props_type.typeName);
282282
const interface_node = this.interface_map.get(name);
283283
if (interface_node) {
284284
this.props_interface.name = name;
@@ -287,9 +287,9 @@ export class HoistableInterfaces {
287287
}
288288
} else {
289289
this.props_interface.name = '$$ComponentProps';
290-
this.props_interface.node = generic_arg;
290+
this.props_interface.node = props_type;
291291
this.collectTypeDependencies(
292-
generic_arg,
292+
props_type,
293293
this.props_interface.type_deps,
294294
this.props_interface.value_deps,
295295
[],

0 commit comments

Comments
 (0)