breaking(types): type arrays as read-only (#1335)

Closes #1259

* breaking(types): type arrays as read-only

* Run "yarn build:docs"

* test: assert read-only arrays
This commit is contained in:
metonym 2022-06-05 13:25:43 -07:00 committed by GitHub
commit 260bf4e040
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 257 additions and 192 deletions

View file

@ -1,16 +1,41 @@
<script lang="ts">
import { Dropdown, DropdownSkeleton } from "../types";
import type { DropdownProps } from "../types/Dropdown/Dropdown.svelte";
let items: DropdownProps["items"] = [
{ id: 0, text: "Slack" },
{ id: "1", text: "Email" },
{ id: "2", text: "Fax" },
] as const;
let itemsWithoutConst = [...items];
type FieldId = typeof items[number]["id"]; // 'foo' | 'bar' | 'baz'
export const fieldId: FieldId = "bar";
// @ts-expect-error
$: items[0] = { id: "0", text: "Slack" };
$: {
// @ts-expect-error
items[0] = { id: "0", text: "Slack" };
}
$: {
items = [...items, { id: "3", text: "Email" }];
items = items.map((item, index) => {
if (index === 0) {
return { id: "0", text: "Slack" };
}
return item;
});
}
</script>
<Dropdown
direction="top"
titleText="Contact"
selectedId="0"
items="{[
{ id: 0, text: 'Slack' },
{ id: '1', text: 'Email' },
{ id: '2', text: 'Fax', disabled: true },
]}"
items="{items}"
on:select="{(e) => {
console.log(e.detail.selectedId);
}}"
@ -31,11 +56,7 @@
}}"
titleText="Contact"
selectedId="0"
items="{[
{ id: '0', text: 'Slack' },
{ id: '1', text: 'Email' },
{ id: '2', text: 'Fax' },
]}"
items="{itemsWithoutConst}"
/>
<Dropdown