Skip to content

Commit

Permalink
(fix) better backwards compatibility (#1640)
Browse files Browse the repository at this point in the history
for new transformation
#1352

This adds additional types to
- incorporate custom element definitions into the new transformation
- override instead of merge type definitions
- allow easy SVGAttributes enhancement in the new trasnformation
  • Loading branch information
dummdidumm committed Sep 16, 2022
1 parent 513f935 commit 37599b9
Show file tree
Hide file tree
Showing 7 changed files with 482 additions and 7 deletions.
@@ -0,0 +1,112 @@
[
{
"range": {
"start": { "line": 12, "character": 19 },
"end": { "line": 12, "character": 20 }
},
"severity": 4,
"source": "ts",
"message": "Parameter 'e' implicitly has an 'any' type, but a better type may be inferred from usage.",
"code": 7044,
"tags": []
},
{
"range": {
"start": { "line": 21, "character": 19 },
"end": { "line": 21, "character": 20 }
},
"severity": 4,
"source": "ts",
"message": "Parameter 'e' implicitly has an 'any' type, but a better type may be inferred from usage.",
"code": 7044,
"tags": []
},
{
"range": {
"start": { "line": 11, "character": 5 },
"end": { "line": 11, "character": 12 }
},
"severity": 1,
"source": "ts",
"message": "Type '{ owntype: string; }' is not assignable to type 'HTMLProps<HTMLDivElement>'.\n Property 'owntype' does not exist on type 'HTMLProps<HTMLDivElement>'.",
"code": 2322,
"tags": []
},
{
"range": {
"start": { "line": 12, "character": 5 },
"end": { "line": 12, "character": 16 }
},
"severity": 1,
"source": "ts",
"message": "Type '{ onownclick: (e: any) => any; }' is not assignable to type 'HTMLProps<HTMLDivElement>'.\n Property 'onownclick' does not exist on type 'HTMLProps<HTMLDivElement>'. Did you mean 'onclick'?",
"code": 2322,
"tags": []
},
{
"range": {
"start": { "line": 19, "character": 5 },
"end": { "line": 19, "character": 12 }
},
"severity": 1,
"source": "ts",
"message": "Type '{ owntype: boolean; }' is not assignable to type 'HTMLProps<HTMLDivElement>'.\n Property 'owntype' does not exist on type 'HTMLProps<HTMLDivElement>'.",
"code": 2322,
"tags": []
},
{
"range": {
"start": { "line": 20, "character": 5 },
"end": { "line": 20, "character": 19 }
},
"severity": 1,
"source": "ts",
"message": "Type 'boolean' is not assignable to type 'string'.",
"code": 2322,
"tags": []
},
{
"range": {
"start": { "line": 21, "character": 5 },
"end": { "line": 21, "character": 16 }
},
"severity": 1,
"source": "ts",
"message": "Type '{ onownclick: (e: any) => any; }' is not assignable to type 'HTMLProps<HTMLDivElement>'.\n Property 'onownclick' does not exist on type 'HTMLProps<HTMLDivElement>'. Did you mean 'onclick'?",
"code": 2322,
"tags": []
},
{
"range": {
"start": { "line": 22, "character": 41 },
"end": { "line": 22, "character": 46 }
},
"severity": 1,
"source": "ts",
"message": "Property 'wrong' does not exist on type '{ foo: string; }'.",
"code": 2339,
"tags": []
},
{
"range": {
"start": { "line": 24, "character": 22 },
"end": { "line": 24, "character": 31 }
},
"severity": 1,
"source": "ts",
"message": "Type 'boolean' is not assignable to type 'string'.",
"code": 2322,
"tags": []
},
{
"range": {
"start": { "line": 25, "character": 22 },
"end": { "line": 25, "character": 32 }
},
"severity": 1,
"source": "ts",
"message": "Type '{ doesnexist: string; }' is not assignable to type '{ attribute?: string; }'.\n Property 'doesnexist' does not exist on type '{ attribute?: string; }'.",
"code": 2322,
"tags": []
}
]
@@ -0,0 +1,90 @@
[
{
"range": {
"start": { "line": 15, "character": 13 },
"end": { "line": 15, "character": 22 }
},
"severity": 1,
"source": "ts",
"message": "Type 'boolean' is not assignable to type 'string'.",
"code": 2322,
"tags": []
},
{
"range": {
"start": { "line": 16, "character": 13 },
"end": { "line": 16, "character": 30 }
},
"severity": 1,
"source": "ts",
"message": "Argument of type '{ doesnexist: string; }' is not assignable to parameter of type '{ attribute?: string; }'.\n Object literal may only specify known properties, and '\"doesnexist\"' does not exist in type '{ attribute?: string; }'.",
"code": 2345,
"tags": []
},
{
"range": {
"start": { "line": 19, "character": 5 },
"end": { "line": 19, "character": 12 }
},
"severity": 1,
"source": "ts",
"message": "Type 'boolean' is not assignable to type 'string'.",
"code": 2322,
"tags": []
},
{
"range": {
"start": { "line": 20, "character": 5 },
"end": { "line": 20, "character": 19 }
},
"severity": 1,
"source": "ts",
"message": "Type 'boolean' is not assignable to type 'string'.",
"code": 2322,
"tags": []
},
{
"range": {
"start": { "line": 21, "character": 34 },
"end": { "line": 21, "character": 39 }
},
"severity": 1,
"source": "ts",
"message": "Property 'wrong' does not exist on type '{ foo: string; }'.",
"code": 2339,
"tags": []
},
{
"range": {
"start": { "line": 22, "character": 41 },
"end": { "line": 22, "character": 46 }
},
"severity": 1,
"source": "ts",
"message": "Property 'wrong' does not exist on type '{ foo: string; }'.",
"code": 2339,
"tags": []
},
{
"range": {
"start": { "line": 24, "character": 22 },
"end": { "line": 24, "character": 31 }
},
"severity": 1,
"source": "ts",
"message": "Type 'boolean' is not assignable to type 'string'.",
"code": 2322,
"tags": []
},
{
"range": {
"start": { "line": 25, "character": 22 },
"end": { "line": 25, "character": 39 }
},
"severity": 1,
"source": "ts",
"message": "Argument of type '{ doesnexist: string; }' is not assignable to parameter of type '{ attribute?: string; }'.\n Object literal may only specify known properties, and '\"doesnexist\"' does not exist in type '{ attribute?: string; }'.",
"code": 2345,
"tags": []
}
]
@@ -0,0 +1,26 @@
<script lang="ts"></script>

<!-- valid for both -->
<div owntypefromold="foo" />
<div on:ownclickfromold={(e) => e.detail.foo} />

<own-element attribute="foo" />

<own-element-from-old attribute="foo" />

<!-- valid for new, invalid for old -->
<div owntype="foo" />
<div on:ownclick={(e) => e.detail.foo} />

<!-- valid for old, invalid for new -->
<own-element attribute={false} />
<own-element doesnexist="wrong" />

<!-- invalid -->
<div owntype={false} />
<div owntypefromold={false} />
<div on:ownclick={(e) => e.detail.wrong} />
<div on:ownclickfromold={(e) => e.detail.wrong} />

<own-element-from-old attribute={false} />
<own-element-from-old doesnexist="wrong" />
@@ -0,0 +1,24 @@
/* eslint-disable */
declare namespace svelte.JSX {
interface HTMLAttributes {
owntypefromold?: string;
onownclickfromold?: (event: CustomEvent<{ foo: string }>) => void;
}
interface IntrinsicElements {
'own-element-from-old': {
attribute?: string;
};
}
}

declare namespace svelteHTML {
interface HTMLAttributes {
owntype?: string;
'on:ownclick'?: (event: CustomEvent<{ foo: string }>) => void;
}
interface IntrinsicElements {
'own-element': {
attribute?: string;
};
}
}
@@ -0,0 +1,9 @@
{
"compilerOptions": {
/**
This is actually not needed, but makes the tests faster
because TS does not look up other types.
*/
"types": ["svelte"]
}
}
Expand Up @@ -3,15 +3,15 @@
"range": { "start": { "line": 9, "character": 5 }, "end": { "line": 9, "character": 19 } },
"severity": 1,
"source": "ts",
"message": "Argument of type '{ \"this-is\": string; }' is not assignable to parameter of type 'HTMLAttributes<...> & EventsWithColon<HTMLProps<HTMLDivElement>> & svelteHTML.HTMLAttributes<...>'.\n Object literal may only specify known properties, and '\"this-is\"' does not exist in type 'HTMLAttributes<...> & EventsWithColon<HTMLProps<HTMLDivElement>> & svelteHTML.HTMLAttributes<...>'.",
"message": "Argument of type '{ \"this-is\": string; }' is not assignable to parameter of type 'HTMLProps<\"div\", HTMLAttributes<any>>'.\n Object literal may only specify known properties, and '\"this-is\"' does not exist in type 'HTMLProps<\"div\", HTMLAttributes<any>>'.",
"code": 2345,
"tags": []
},
{
"range": { "start": { "line": 10, "character": 6 }, "end": { "line": 10, "character": 9 } },
"severity": 1,
"source": "ts",
"message": "Argument of type '{ bar: string; }' is not assignable to parameter of type 'HTMLAttributes<...> & EventsWithColon<HTMLProps<HTMLDivElement>> & svelteHTML.HTMLAttributes<...>'.\n Object literal may only specify known properties, and 'bar' does not exist in type 'HTMLAttributes<...> & EventsWithColon<HTMLProps<HTMLDivElement>> & svelteHTML.HTMLAttributes<...>'.",
"message": "Argument of type '{ bar: string; }' is not assignable to parameter of type 'HTMLProps<\"div\", HTMLAttributes<any>>'.\n Object literal may only specify known properties, and 'bar' does not exist in type 'HTMLProps<\"div\", HTMLAttributes<any>>'.",
"code": 2345,
"tags": []
}
Expand Down

0 comments on commit 37599b9

Please sign in to comment.