Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict mode: hash is required to be imported, but glint reports it as not used. #374

Closed
NullVoxPopuli opened this issue Jul 24, 2022 · 8 comments · Fixed by #453
Closed
Labels
bug Something isn't working

Comments

@NullVoxPopuli
Copy link
Contributor

Sample gjs:

import { hash } from '@ember/helper';

<template>{{yield (hash x=1)}}</template>

Sample Error:

app/components/limber/output/compiler/index.gts:3:1 - error TS6133: 'hash' is declared but its value is never read.

3 import { hash } from '@ember/helper';

Since removing the import creates a runtime error, "hash is not defined", I think Glint should not report the hash import as never read?

I'm using

  • ember-source 4.5
  • ember-template-imports 3.0.1
  • @glint* 0.9.1
@NullVoxPopuli NullVoxPopuli changed the title Strict mode: hash is required to be imported, but glint reporst it as not used. Strict mode: hash is required to be imported, but glint reports it as not used. Jul 24, 2022
@dfreeman dfreeman added the bug Something isn't working label Jul 27, 2022
@dfreeman
Copy link
Member

dfreeman commented Jul 27, 2022

This is why I want dedicated template syntax for object and array literals 😂

This is definitely a bug, but will need to think a bit on how to best address it. (Note: {{array}} will have this same problem)

@NullVoxPopuli
Copy link
Contributor Author

NullVoxPopuli commented Jul 27, 2022

you and me both <3

I don't think I captured that in emberjs/rfcs#816 🤔
do you know of any in-progress things I should like to from that meta issue?

@dfreeman
Copy link
Member

I remember during discussions around the default helper manager, there was some discussion that it would be easier to avoid supporting named args if there were dedicated object syntax (basically just 1:1 parity with JS function invocation), but I don't know that that was ever actually captured anywhere.

@ef4
Copy link
Contributor

ef4 commented Sep 8, 2022

Instead of compiling (hash a=b) directly to ({ a: b }) it could compile to (χ.noop(hash), { a: b }).

I confirmed that this keeps typescript's strict object literal handling, in the sense that it makes unused keys into type errors.

@dfreeman
Copy link
Member

dfreeman commented Sep 9, 2022

Ah, that's clever. Using an empty array literal as a canary (both because I know that's particularly fragile inference behavior in TS and because it could affect us with {{array}}), it looks like that approach can impact the propagation of type info: https://www.typescriptlang.org/play?#code/DYUwLgBAHhC8EG0C6BuAUFFED02IEMA7AT2TQwDoAHAVwGcALACgEYAmAZgEp1Mc9CNALYAjEACcy5NKEjE4EJgAYANIiQ80xLLgiEQANwlTi1es3bcdeAILiA5sJCFIAewBmEMMSogIAckFRCX8IAEs6PVdIfDo6MPtCfBFQL1cIKnxxfCFwCQgPLx8-QMMQiiA

I think we'd want to be careful to make sure that there aren't situations where this can impact inference users may rely on in templates, but if not I like the comma expression approach. Thanks for the suggestion!

@NullVoxPopuli
Copy link
Contributor Author

with hash, don't the individual values track separately as well? like, if we switched to an object literal, we'd forcibly entangle all values with the whole object?

@ef4
Copy link
Contributor

ef4 commented Sep 9, 2022

It already compiles to an object literal. But this isn't code that runs, it's just code that tsc looks at.

@wagenet
Copy link
Contributor

wagenet commented Oct 28, 2022

Is this just waiting on someone to do the work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants