Optional props: Type is not assignable to type 'IntrinsicAttributes & ...'.
See original GitHub issueDescribe the bug I have a component like this:
<script lang="ts">
export let width = "100%";
export let height = "100px";
export let responsive = false;
</script>
<div id="categorySelect" style="width: {width}; height: {height};" />
If I use this component from another component but do not define the width: <Abc height="100%" responsive={true} />
, VSCode shows the following error:
Type '{ height: string; responsive: true; }' is not assignable to type 'IntrinsicAttributes & { width: string; height: string; responsive: boolean; }'.
Property 'width' is missing in type '{ height: string; responsive: true; }' but required in type '{ width: string; height: string; responsive: boolean; }
Therefore I tried explicitly defining width as string | undefined:
<script lang="ts">
export let width: string | undefined = "100%";
export let height = "100px";
export let responsive = false;
</script>
<div id="categorySelect" style="width: {width}; height: {height};" />
Now I get this error:
Type 'true' is not assignable to type 'false'
It complains because I am setting another value than the default value.
Most strangely, adding an event handler for an event which doesn’t even exist fixes the errors:
<Abc height="100%" on:bla={e => {}} responsive={true} />
Expected behavior It should be possible to skip properties with default value or use other values than the default value.
System (please complete the following information):
- OS: Windows 10
- IDE: VSCode 1.47.2
- Plugin/Package: “Svelte for VSCode 101.3.0”
"svelte": "^3.24.0",
"svelte-check": "^0.1.55",
"svelte-loader": "^2.13.6",
"svelte-preprocess": "^4.0.8",
"@tsconfig/svelte": "^1.0.3",
"typescript": "^3.9.7",
tsconfig:
{
"extends": "@tsconfig/svelte/tsconfig.json",
"include": [
"src/**/*",
"src/node_modules"
],
"exclude": [
"node_modules/*",
"dist/*"
],
"compilerOptions": {
"strict": true,
"resolveJsonModule": true,
"sourceMap": true
}
}
Additional context This is so strange, maybe something with my setup is wrong? Related: #276
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Quick update: Of the three bugs only
let a = false
has a type of false, not booleanstill exists, which can be worked around by doing
let a: boolean = false
Closing in favor of #588