typed-ember / glint

TypeScript powered tooling for Glimmer templates
https://typed-ember.gitbook.io/glint
MIT License
110 stars 51 forks source link

Different behavior checking a project with `glint` vs. `glint --build` #525

Closed NullVoxPopuli closed 1 year ago

NullVoxPopuli commented 1 year ago

Repro:

1

2   {{outlet}}

3


app/templates/application.hbs:1:3 - error TS7053: Unknown name 'page-title'. If this isn't a typo, you may be missing a registry entry for this value; see the Template Registry page in the Glint documentation for more details.
  Element implicitly has an 'any' type because expression of type '"page-title"' can't be used to index type 'Globals'.
    Property 'page-title' does not exist on type 'Globals'.

1 {{page-title "ember-headless-table"}}

app/templates/application.hbs:3:1 - error TS7053: Unknown name 'App'. If this isn't a typo, you may be missing a registry entry for this value; see the Template Registry page in the Glint documentation for more details. Element implicitly has an 'any' type because expression of type '"App"' can't be used to index type 'Globals'. Property 'App' does not exist on type 'Globals'.

3

  4   <:topBar>

... 44 </:content>

 45 </App>

app/templates/index.hbs:2:1 - error TS7053: Unknown name 'Hero'. If this isn't a typo, you may be missing a registry entry for this value; see the Template Registry page in the Glint documentation for more details. Element implicitly has an 'any' type because expression of type '"Hero"' can't be used to index type 'Globals'. Property 'Hero' does not exist on type 'Globals'.

2

  3   <div class="grid gap-8" id="skip-to-target">

...

app/templates/index.hbs:51:9 - error TS7053: Unknown name 'FeatureCard'. If this isn't a typo, you may be missing a registry entry for this value; see the Template Registry page in the Glint documentation for more details. Element implicitly has an 'any' type because expression of type '"FeatureCard"' can't be used to index type 'Globals'. Property 'FeatureCard' does not exist on type 'Globals'.

51 <FeatureCard @title="Toggle column visibility">

52           Different users find different data important. Enable them to hide what they don't care about, and show what they do care about.

53


app/templates/index.hbs:55:9 - error TS7053: Unknown name 'FeatureCard'. If this isn't a typo, you may be missing a registry entry for this value; see the Template Registry page in the Glint documentation for more details.
  Element implicitly has an 'any' type because expression of type '"FeatureCard"' can't be used to index type 'Globals'.
    Property 'FeatureCard' does not exist on type 'Globals'.

55         <FeatureCard @title="Reordering columns">

56 Change the order of columns.

57         </FeatureCard>

app/templates/index.hbs:59:9 - error TS7053: Unknown name 'FeatureCard'. If this isn't a typo, you may be missing a registry entry for this value; see the Template Registry page in the Glint documentation for more details. Element implicitly has an 'any' type because expression of type '"FeatureCard"' can't be used to index type 'Globals'. Property 'FeatureCard' does not exist on type 'Globals'.

59 <FeatureCard @title="Resizable columns">

60           Accessibly change the width of columns with the mouse or keyboard.

61


app/templates/index.hbs:63:9 - error TS7053: Unknown name 'FeatureCard'. If this isn't a typo, you may be missing a registry entry for this value; see the Template Registry page in the Glint documentation for more details.
  Element implicitly has an 'any' type because expression of type '"FeatureCard"' can't be used to index type 'Globals'.
    Property 'FeatureCard' does not exist on type 'Globals'.

63         <FeatureCard @title="Data Sorting">

64 Change the order of data. Integrate with your existing sorting APIs.

65         </FeatureCard>

app/templates/index.hbs:67:9 - error TS7053: Unknown name 'FeatureCard'. If this isn't a typo, you may be missing a registry entry for this value; see the Template Registry page in the Glint documentation for more details. Element implicitly has an 'any' type because expression of type '"FeatureCard"' can't be used to index type 'Globals'. Property 'FeatureCard' does not exist on type 'Globals'.

67 <FeatureCard @title="Sticky columns">

68           Pin columns to the left or right side of the table so that they stick to that side.

69



Error: Process completed with exit code 1.
 ```

 </details>

 - `glint --build`: https://github.com/CrowdStrike/ember-headless-table/pull/118/commits/6d3c9af4f562ba740792215522f18979dd372c81

  <details><summary>log output in case GH Action retention expires</summary>

 ```
 pnpm glint --build
  shell: /usr/bin/bash -e {0}
  env:
    CI: true
    dist: ember-headless-table/dist
    PNPM_HOME: /home/runner/setup-pnpm/node_modules/.bin
DeprecationWarning: 'createImportDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
 ```

 </details>
dfreeman commented 1 year ago

After reverse engineering your CI setup to be able to reproduce this issue myself, it looks like you've hit a pnpm bug.

The copy of @glint/environment-ember-loose that's visible from your docs-app is @glint+environment-ember-loose@0.9.7_q3dyqagzoarn5fdnpc2fuow56q, but the copy that's visible from docs-app's copy of @glint/environment-ember-template-imports is @glint+environment-ember-loose@0.9.7_t5ycb63yys2yccfcq5mlxlwezm.

Given that @glint/environment-ember-loose is declared as a peerDependency of @glint/environment-ember-template-imports, it should be the same copy of the package that's visible from both places, but that's not the case — it appears that ETI is instead seeing the copy that "belongs to" your test-app workspace instead.

Because of this, the order in which module resolution happens is impacting which copy of environment-ember-loose your Registry declarations get merged into. Due to implementation details within TypeScript itself, some modes (like --watch and --build) happen to resolve in an order where they land where you'd want, but others (like single-pass glint and what the language server sees) wind up merging the declarations into the other copy instead.

NullVoxPopuli commented 1 year ago

I tested this via re-rolling my lockfile diff here, and now the type checking is passing.

So -- maybe more specifically, it seems that the lockfile doesn't invalidate as frequently as it should.

I'll bring this up with the pnpm folks. https://github.com/pnpm/pnpm/issues/5986