uncenter / eleventy-plugin-icons

✨ A plugin for Eleventy to add and transform icons from any icon set.
https://www.npmjs.com/package/eleventy-plugin-icons
MIT License
11 stars 0 forks source link

Options types are incorrect for consumer #109

Closed nathonius closed 2 months ago

nathonius commented 2 months ago

When providing options when loading the plugin, provided options are merged with the default; however, the types don't reflect this:

// icons.ts
import IconsPlugin from "eleventy-plugin-icons";
import { EleventyConfig } from "../11ty";

export function icons(config: EleventyConfig) {
  config.addPlugin(IconsPlugin, {
    sources: [
      {
        name: "lucide",
        path: "node_modules/lucide-static/icons",
        default: true,
      },
    ],
    icon: { // ERROR HERE
      attributes: {
        "aria-hidden": "true",
      },
    },
  });
}

// Error:
Type '{ attributes: { "aria-hidden": string; }; }' is missing the following properties
from type '{ shortcode: string; delimiter: string; transform: (content: string) =>
Promise<string>; class: (name: string, source: string) => string; id: (name: string,
source: string) => string; attributes: { ...; }; attributesBySource: { ...; };
overwriteExistingAttributes: boolean; errorNotFound: boolean; }': shortcode, delimiter,
transform, class, and 4 more.ts(2740)

Very low priority since typescript support with 11ty is very unofficial.

uncenter commented 1 month ago

I hope that fixed your issue!

nathonius commented 1 month ago

I hope that fixed your issue!

Tried it today; it does and also doesn't. There's no error when specifying a partial, so the typings are valid in that sense, but they do let me now specify properties on the options that don't exist.

This is valid:

  config.addPlugin(IconsPlugin, {
    abc: 'xyz', // abc: string
    sources: [
      {
        name: "lucide",
        path: "node_modules/lucide-static/icons",
        default: true,
      },
    ],
    icon: {
      attributes: {
        "aria-hidden": "true",
      },
    },
  });

Examining the type on the object it just says whatever I've specified, though it is typed enough that VS Code can auto-complete the valid properties of the type when asked. So, good enough for me.