NullVoxPopuli / ember-resources

An implementation of Resources. Supports ember 3.28+
https://github.com/NullVoxPopuli/ember-resources/blob/main/docs/docs/README.md
MIT License
90 stars 37 forks source link

Types for resource return value in gjs/gts incorrect with Glint #1153

Closed knownasilya closed 1 month ago

knownasilya commented 1 month ago
export const ExampleResource = resource(() => {
  const item = cell(1);

  return item;
});

When used like so:

{{#let (ExampleResource) as |val|}}
   use it here
{{/let}}

Shows the following error:

The given value does not appear to be usable as a component, modifier or helper.
  No overload matches this call.
    Overload 1 of 3, '(item: DirectInvokable): AnyFunction', gave the following error.
      Argument of type 'Cell<number>' is not assignable to parameter of type 'DirectInvokable'.
        Property '[InvokeDirect]' is missing in type 'Cell<number>' but required in type 'DirectInvokable'.
    Overload 2 of 3, '(item: (abstract new (...args: unknown[]) => InvokableInstance) | null | undefined): (...args: any[]) => any', gave the following error.
      Argument of type 'Cell<number>' is not assignable to parameter of type 'abstract new (...args: unknown[]) => InvokableInstance'.
        Type 'Cell<number>' provides no match for the signature 'new (...args: unknown[]): InvokableInstance'.
    Overload 3 of 3, '(item: ((...params: any) => any) | null | undefined): (...params: any) => any', gave the following error.
      Argument of type 'Cell<number>' is not assignable to parameter of type '(...params: any) => any'.
        Type 'Cell<number>' provides no match for the signature '(...params: any): any'.glint(2769)

Versions:

 "ember-resources": "^7.0.2",
    "ember-route-template": "^1.0.3",
    "ember-source": "~5.11.0",
    "ember-template-imports": "^4.1.1",
    "typescript": "^5.6.2",
   "@glint/core": "^1.4.0",
    "@glint/environment-ember-loose": "^1.4.0",
    "@glint/environment-ember-template-imports": "^1.4.0",
    "@glint/template": "^1.4.0",
NullVoxPopuli commented 1 month ago

So I thought this was a bug, but there is actually no way to make it work (with Glint, afaict)

You don't need let or () here.

You can just do {{ExampleResource}}

knownasilya commented 1 month ago

I actually needed () when using a cell with an object inside an each-in, otherwise it only rendered the keys of the cell, not it's value.

NullVoxPopuli commented 1 month ago

Can you provide a repro for that behavior? that seems fishy