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

chore: Fix main branch typescript errors #83

Merged
merged 12 commits into from
May 25, 2023
Merged

chore: Fix main branch typescript errors #83

merged 12 commits into from
May 25, 2023

Conversation

ynotdraw
Copy link
Contributor

@ynotdraw ynotdraw commented May 17, 2023

Description

Get the build for this repo green again so that we can put up a PR to export the Glint Template Registry. Once we have the registry, we can use this in toucan-core to create Popover, Select, and Multiselect properly.

Here's everything this PR covers:

  • Drop TS support less than 4.8. Glint only supports TS 4.8+
  • Upgrade Glint dependencies to latest v1
  • Fix TS errors around "owner"/"Resolver"
  • Add @ember/string as a dependency
  • Resolve TS errors in tests. Likely need to extend the TestContext due to using this.setProperties
  • Drop commitlint
    • Our other open source repos dropped this and moved to change sets instead
    • I am happy to move this over to changesets for consistency in a follow up PR as I feel like all of our open source repos we work in regularly should follow similar conventions for DX
    • See this comment

⚠️ NOTE: ⚠️ We'll want to do a breaking change release due to dropping TS support and moving to Glint in another downstream PR. I'm hoping to get this done over the next few days 🤞.

Started getting type errors with resolver:

"Module '"@ember/owner"' has no exported member 'Resolver'. Did you mean to use 'import Resolver from "@ember/owner"' instead?"

ember-resolver now ships with their own types rather than the types namespace
@@ -63,6 +62,7 @@
"@types/ember__engine": "^4.0.4",
"@types/ember__error": "^4.0.2",
"@types/ember__object": "^4.0.5",
"@types/ember__owner": "^4.0.3",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this, otherwise when running glint we get the following:

../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@types/ember__application/index.d.ts:17:17 - error TS2614: Module '"@ember/owner"' has no exported member 'Resolver'. Did you mean to use 'import Resolver from "@ember/owner"' instead?

17 import Owner, { Resolver } from '@ember/owner';
                   ~~~~~~~~

../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@types/ember__debug/container-debug-adapter.d.ts:1:10 - error TS2614: Module '"@ember/owner"' has no exported member 'Resolver'. Did you mean to use 'import Resolver from "@ember/owner"' instead?

1 import { Resolver } from '@ember/owner';
           ~~~~~~~~

../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@types/ember__engine/index.d.ts:15:10 - error TS2614: Module '"@ember/owner"' has no exported member 'Resolver'. Did you mean to use 'import Resolver from "@ember/owner"' instead?

15 import { Resolver } from '@ember/owner';
            ~~~~~~~~

../node_modules/.pnpm/[email protected]_j5milmbhnvuuqbh2i3lfyo7nii/node_modules/ember-qunit/types/index.d.ts:10:10 - error TS2614: Module '"@ember/owner"' has no exported member 'Resolver'. Did you mean to use 'import Resolver from "@ember/owner"' instead?

10 import { Resolver } from '@ember/owner';
            ~~~~~~~~

../node_modules/.pnpm/[email protected][email protected]/node_modules/ember-resolver/index.d.ts:1:10 - error TS2614: Module '"@ember/owner"' has no exported member 'Resolver'. Did you mean to use 'import Resolver from "@ember/owner"' instead?

1 import { Resolver as ResolverContract } from "@ember/owner";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also the option to use the built in types for easier addon dev!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of giving those a go! It'd be nice to remove all of the @types/ember__ packages.

While I have you here - do you happen to know why glint seemingly type checks within node_modules like this? I'm used to Next.js projects where the tsconfig uses skipLibCheck: true and we don't get these types of issues. As a test, I added skipLibCheck in the tsconfig and I no longer got this error, but then realized I needed to add this dependency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glint seemingly type checks within node_modules like this?

TS (and Glint) must derive the types you use somehow, they can't just come from nowhere, ya know?

I'm used to Next.js projects where the tsconfig uses skipLibCheck: true

as a library author / maintainer, one may not use skipLibCheck safely because it propagates hidden errors to consumers.
The library one authors must be as correct as reasonable, and skipLibCheck accidentally avoids that correctness.
It's only reasonable to use in apps / or maybe aka "endpoint consumers".

Additionally, to be the best stewards we can be, every library author probably wants to have these settings, if using pnpm:
https://github.com/emberjs/rfcs/pull/907/files#diff-116076a2d4078dfbf8de672a7b681ed1635715f3acfbfd31a1e7009251eef70dR123

# all peer dependencies must be declared or forwarded to the consumer
auto-install-peers=false
# we want true isolation in addons -- if a dependency is not declared, we want an error
reslove-peers-from-workspace-root=false

but then realized I needed to add this dependency.

you'll likely have a lot less issues with the built in types.
The way DT manages types by allowing all chaos via * dep ranges is madness. They are doing their best though. but it's madness.

Here is an example PR I did recently for the v2 addon bluerpint to adopt the built in types.
embroider-build/addon-blueprint#118

Errors / @types/etc

Regarding your errors though, you may have the quickest (and smallest diff) luck by

  • upgrading all type deps to latest
  • deleting the lockfile
  • re-install (re-generating the lockfile)
  • remove @types for packages which now ship their own types (ember-resolver, @ember/string, @ember/test-helpers, etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is super helpful! Thank you! 🙇

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reslove-peers-from-workspace-root=false

Just checking that you didn't copy paste that from somewhere? I guess it's probably meant to be resolve although everyone could do with some res love!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol. yeah, it's a typo. resolve is correct 🙈

@ynotdraw ynotdraw self-assigned this May 19, 2023
Copy link
Contributor Author

@ynotdraw ynotdraw May 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glint requires typescript >= 4.8. We had a similar PR here

@@ -137,6 +137,8 @@ module('Integration | Component | velcro', function (hooks) {
<div {{velcro.hook}}>velcroReference</div>
<div id="velcro1" {{velcro.loop}}>Velcro</div>
</Velcro>
{{!-- Having an issue referencing a typed 'this' in the modifier --}}
{{! @glint-ignore }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I couldn't get this context to be my extended TestContext following something like: https://github.com/typed-ember/ember-cli-typescript/blob/master/docs/ember/testing.md#addon-tests

  test('can pass in distance', async function (this: TestContext & {
    offsetDistance: number;
  }, assert) {
    let offsetDistance = 10;

    this.set('offsetDistance', offsetDistance);
    // This doesn't work either
    // this.offsetDistance = offsetDistance;

    await render(hbs`
      <div style="display: flex">
        <Velcro @placement="bottom-start" as |velcro|>
          <div {{velcro.hook}}>velcroReference</div>
          <div id="velcro1" {{velcro.loop}}>Velcro</div>
        </Velcro>
        {{!-- "this" here is void! Strange! --}}
        <Velcro @offsetOptions={{this.offsetDistance}} @placement="bottom-start" as |velcro|>
          <div {{velcro.hook}}>velcroReference</div>
          <div id="velcro2" {{velcro.loop}}>Velcro</div>
        </Velcro>
      </div>
    `);

    let velcro1 = findElement('#velcro1');
    let velcro2 = findElement('#velcro2');

    assert.strictEqual(
      velcro1.getBoundingClientRect().top + offsetDistance,
      velcro2.getBoundingClientRect().top
    );
  });

Whenever this is referenced in the template, it says the type is void and points to @glint/template's TemplateContext rather than the overriding test context. Any pointers here would be wonderful!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo, best to use gts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do! Thanks as always, @NullVoxPopuli ! 🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went ahead and deleted this as our other repos are no longer including this due to the move to changesets where we can control releases and commits can be squashed with helpful messages anyway. Getting errors in CI about commits is really tough, especially when the error messages aren't helpful at all.

We don't want to create a release just yet using semantic-release anyway, as there's still more to do to get this completely functional with toucan-core + Glint in general for external consumers. For example, we'll need to add an exported template-registry. I plan on doing this right after this PR merges, as I want to keep PRs as small as possible so they're easier to follow.

{{object-keys velcro.data}}
{{#each-in velcro.data as |key|}}
{{key}}
{{/each-in}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glint was having issues with recognizing object-keys, so I reached for #each-in instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also isn't available as a global as globals don't exist in gts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so that's why Glint wasn't recognizing it. Makes sense! 🎉

@ynotdraw ynotdraw marked this pull request as ready for review May 22, 2023 18:13
"@glint/environment-ember-loose": "^0.9.4",
"@glint/template": "^0.9.5"
"@glint/environment-ember-loose": "^1.0.2",
"@glint/template": "^1.0.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this PR didn't change this, but I wonder why we have these as peer deps? Other similar addons with Glint support don't have this, same for the addon blueprint. At least they should be optional, as non-TS shouldn't be force to install them. But I think it should be enough to have them as devDeps!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I agree here, nice call out. This should be resolved now with the latest commit

"@nullvoxpopuli/eslint-configs": "^2.2.58",
"@tsconfig/ember": "^1.1.0",
"@types/ember": "^4.0.3",
"@types/ember-qunit": "^5.0.2",
"@types/ember-resolver": "^5.0.13",
"@types/ember-qunit": "^6.1.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need these with the latest ember-qunit, which ships its own types. Same for @types/ember__test-helpers below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This should be resolved now with the latest commit


assert
.dom('#hook')
.hasText(
'x,y,initialPlacement,placement,strategy,middlewareData,rects,platform,elements',
'x y initialPlacement placement strategy middlewareData rects platform elements',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know what this means, but is this change expected?

Copy link
Contributor Author

@ynotdraw ynotdraw May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! Up above we are essentially writing out the object keys to the DOM and asserting what's returned there with:

{{#each-in velcro.data as |key|}}
  {{key}}
{{/each-in}}

Previously we were using object-keys which would comma-separate them, but Glint wouldn't recognize that, so I switched to each-in which is why it went from comma-separated to space-separated.

Alternatively, we could do something more verbose and explicit though. Maybe something like:

test('it yields the MiddlewareArguments', async function (assert) {
  await render(<template>
      <Velcro as |velcro|>
        <div id="hook" {{velcro.hook}}>
          <ul>
            {{#each-in velcro.data as |key|}}
              <li data-velcro="{{key}}">{{key}}</li>
            {{/each-in}}
          </ul>
        </div>
        <div id="loop" {{velcro.loop}}>VelcroElement</div>
      </Velcro>
  </template>);

  assert
  .dom('li')
  .exists(
    { count: 9 },
    'has the correct velcro.data object keys'
  );

  assert.dom('[data-velcro="x"]').exists();
  assert.dom('[data-velcro="y"]').exists();
  // etc.
});

Any preference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok, got it. All good!

@@ -127,22 +132,20 @@ module('Integration | Component | velcro', function (hooks) {
test('can pass in distance', async function (assert) {
let offsetDistance = 10;

this.set('offsetDistance', offsetDistance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more stupid set, yay! 😍

Copy link
Contributor

@camskene camskene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!

@ynotdraw ynotdraw mentioned this pull request May 24, 2023
BREAKING CHANGE: Removing types and updating TypeScript version to support Glint properly.

These libraries now ship with their own types, so we no longer need the ones coming from the types namespace anymore.

Co-authored-by: Simon Ihmig <[email protected]>
@changeset-bot
Copy link

changeset-bot bot commented May 25, 2023

⚠️ No Changeset found

Latest commit: 370cb3b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ynotdraw ynotdraw merged commit a732f56 into main May 25, 2023
@ynotdraw ynotdraw deleted the fix-main branch May 25, 2023 14:46
github-actions bot pushed a commit that referenced this pull request May 25, 2023
# [2.0.0](v1.1.0...v2.0.0) (2023-05-25)

* breaking-change: Fix main branch typescript errors (#83) ([a732f56](a732f56)), closes [#83](#83)

### BREAKING CHANGES

* Removing types and updating TypeScript version to support Glint properly. The main branch build is currently red due to the Glint dependency updates.  This gets things back on track.  We are making a breaking change as updating underlying TypeScript changes is considered as such (CrowdStrike/ember-headless-table#176).

* chore: Upgrade glint dependencies

* chore: Allow any ember-source + typescript

* chore: Glint only supports TSv4.8+

* chore: Upgrade ember-source + resolver

Started getting type errors with resolver:

"Module '"@ember/owner"' has no exported member 'Resolver'. Did you mean to use 'import Resolver from "@ember/owner"' instead?"

ember-resolver now ships with their own types rather than the types namespace

* chore: Remove commitlint

* chore: Update babel/core + qunit deps

* chore: Add @types/ember__owner dependency

* chore: Add ember/string as a dependency for tests

* chore: Ignore glint errors for now

* chore: Convert tests to gts

* fix: Remove unneeded peerDependencies

* fix: Remove unneeded types/ember packages

These libraries now ship with their own types, so we no longer need the ones coming from the types namespace anymore.
@github-actions
Copy link
Contributor

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants