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

Install TypeScript, add template registry #13

Merged
merged 12 commits into from
Jul 6, 2024

Conversation

charlesfries
Copy link
Contributor

No description provided.

@lukasnys
Copy link

This is awesome! Anything that can be done to help move this forward?

@charlesfries
Copy link
Contributor Author

@lukasnys I just need some help installing TypeScript in a V2 addon. Not sure exactly what files and deps are needed

@lukasnys
Copy link

@charlesfries I couldn't immediately find a list of commands to easily add TypeScript to a V2 addon. I tried using ember-cli-update and passing the --typescript flag to the blueprint but that didn't work unfortunately.

I then took a different approach and I created 2 V2 addons, one with TS and one without. Then I copied over the contents of the one with TS to the other one and created a PR of those changes: https://github.com/lukasnys/addon-v2-to-typescript/pull/1/files.

Might be a starting point to getting it working? Though @NullVoxPopuli if you know of a list of commands to setup TS in a V2 addon more easily that would be perfect

@NullVoxPopuli
Copy link
Owner

I think if the typescript flag exist in the ember-cli-update.json, ember-cli-update will tell you what to add? Haven't tried, but just an idea.

Otherwise, the needed changes are in

  • babel.config
  • tsconfig
  • rollup.config
  • each runtime file (imported extensions change
  • template-registry.ts
  • package.json

@charlesfries
Copy link
Contributor Author

Pushed a WIP TypeScript installation. This is the issue I'm hitting now:

RollupError: Could not resolve "../utils/as-array" from "src/helpers/chunk.ts"

Tried adding utils/**/*.js to the Rollup appReexports to no avail

@NullVoxPopuli
Copy link
Owner

in a v2 addon, you need to include the file extensions on the imports, so ../utils/as-array.ts

@charlesfries
Copy link
Contributor Author

charlesfries commented Jul 2, 2024

Thanks for the tip. It now seems to build correctly.

I'm now only seeing Cannot find module 'rsvp' or its corresponding type declarations.. I tried installing @types/rsvp in the ember-composable-helpers app but that doesn't seem to fix it. test-app already includes that types package--is there anywhere else I need to install that to fix that error? Never mind it's working now

@charlesfries charlesfries marked this pull request as ready for review July 2, 2024 21:19
@@ -1,5 +1,6 @@
import Ember from 'ember';
Copy link
Owner

Choose a reason for hiding this comment

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

This is going to be problematic for Ember v7 😅

Copy link
Owner

Choose a reason for hiding this comment

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

I don't think we should introduce this file yet -- we can't use any of these helpers in JS because they still are wrapped with helper

(to use, we require invokeHelper, which is verbose to use)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI this file already existed, I just converted it to TS. Reverted regardless

Copy link
Owner

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

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

some cleanup things to do <3

"concurrently": "^8.2.1",
"ember-source": "~5.8.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed to install this + webpack peer to access built-in types

Copy link
Owner

Choose a reason for hiding this comment

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

makes sense


export function mapBy([byPath, array]) {
export function mapBy<T extends object>([byPath, array]: [keyof T, T[]]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

get types are slightly different with built-in types--would it be preferable to use a type assertion on the get args instead of modifying the generic constraint like I've done here?

Copy link
Owner

Choose a reason for hiding this comment

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

probably, ya

@NullVoxPopuli NullVoxPopuli added the enhancement New feature or request label Jul 3, 2024
@@ -8,6 +8,7 @@
"lint:css:fix": "concurrently \"npm:lint:css -- --fix\"",
"lint:hbs": "ember-template-lint .",
"lint:js": "eslint .",
"lint:types": "glint",
Copy link
Owner

Choose a reason for hiding this comment

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

does this run in CI?

Copy link
Owner

Choose a reason for hiding this comment

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

I don't actually see any linting going on in CI -- can you verify that linting and type checking is happening in the workflow files?

thanks!

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 believe the lint scripts are actually broken on main (at least on my Windows comp) #19

I added pnpm run lint to the test app CI job, which should trigger a lint:types run

@@ -23,6 +23,7 @@ jobs:
- uses: actions/checkout@v4
- uses: wyvox/action-setup-pnpm@v3
- run: pnpm build
- run: pnpm run lint
Copy link
Owner

Choose a reason for hiding this comment

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

can you put this in its own job above test-default?

and then add the lint command to package.json? 😅
https://github.com/NullVoxPopuli/ember-composable-helpers/pull/13/files#diff-b03f4acb30e04ceb12a40763ef649759b3f632df2357bcec14fab6dd29ebbfb4L5

@NullVoxPopuli NullVoxPopuli merged commit 802650c into NullVoxPopuli:main Jul 6, 2024
14 checks passed
@github-actions github-actions bot mentioned this pull request Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants