CrowdStrike/ember-velcro

package published incorrectly and fails type checking in consuming projects

Closed this issue · 2 comments

From npm, the currently published assets:

Screenshot_20240414-085247
image-2~2

Idk what happened to that ember-modifier import, but that's not a valid syntax, afaik

From what I could understand, it seems that the problem is when TypeScript is generating the declaration file, more specifically the return type of modifier for the velcroHook property.
That's when it generates the import("ember-modifier/.") line:

velcroHook: import("ember-modifier/.").FunctionBasedModifier<{
    Element: HTMLElement | SVGElement;
    Args: {
        Named: import("ember-modifier/-private/signature").EmptyObject;
        Positional: [];
    };
}>;

However, if add the following lines on the component's index.ts file

import type { FunctionBasedModifier } from 'ember-modifier';
import type { EmptyObject } from 'ember-modifier/-private/signature.js';

Then this appears to serve as a "hint" to typescript, and the generated declaration is:

import { FunctionBasedModifier } from 'ember-modifier';
import { EmptyObject } from 'ember-modifier/-private/signature.js';

// ...

velcroHook: FunctionBasedModifier<{
    Element: HTMLElement | SVGElement;
    Args: {
        Named: EmptyObject;
        Positional: [];
    };
}>;

I lack the knowledge to instruct typescript to generate the correct declaration, but hopefully this helps.

Another find: in the consuming app, if I go into node_modules/ember-velcro/dist/components/velcro/index.d.ts and make this change

-velcroHook: import("ember-modifier/.").FunctionBasedModifier<{
+velcroHook: import("ember-modifier").FunctionBasedModifier<{
    Args: {
        Positional: unknown[];
        Named: import("ember-modifier/-private/signature").EmptyObject;
    };
    Element: HookSignature;
}>;

then the typecheck on the app works!
So, seems like the only problem is that /.. 🤔