Skip to content

Commit

Permalink
fix: some types of InlineSVG (#1497)
Browse files Browse the repository at this point in the history
- extend the Intrinsic svg html attributes 

instead of explicit type cast, which is more unsafe

- Add `as const`

Which creates more narrow type unions for e.g the color "lightblue" |
"orange" | "green" instead of "string" for the non-const expression
  • Loading branch information
hsjobeki committed Jul 2, 2024
1 parent e43b7f4 commit e67b1b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/components/util/InlineSVG.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import { parse } from "node-html-parser";
// svgo is a peer dependency of astro-icon
import { optimize } from "svgo";
import type { Attributes } from "node-html-parser/dist/nodes/html";
export interface Props {
export interface Props extends Attributes {
src: string;
}
Expand All @@ -12,8 +13,11 @@ interface SVGFile {
file: string;
}
const { src, ...attributes } = Astro.props as Props;
const res = import.meta.glob("/src/**/*.svg", { eager: true, query: "?raw" });
const { src, ...attributes } = Astro.props;
const res = import.meta.glob("/src/**/*.svg", {
eager: true,
query: "?raw",
}) as Record<string, SVGFile>;
if (!(src in res)) {
throw new Error(`${src} not found`);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/learn.astro
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const learningFeatures = [
color: "lightblue",
url: "/guides/how-nix-works",
},
];
] as const;
const learningResources = [
{
Expand All @@ -51,7 +51,7 @@ const learningResources = [
url: "/guides/nix-pills",
buttonText: "Take the Pills",
},
];
] as const;
---

<Layout title="Learn Nix | Nix & NixOS">
Expand Down

0 comments on commit e67b1b3

Please sign in to comment.