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

Convert to TypeScript #450

Merged
merged 14 commits into from
Nov 1, 2018
Merged

Convert to TypeScript #450

merged 14 commits into from
Nov 1, 2018

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Nov 1, 2018

This PR starts the conversion of this addon towards TypeScript

Closes #371

/cc @chriskrycho @mike-north @dfreeman

@chriskrycho
Copy link
Contributor

One quick note here (more later): depending on the sense of urgency you feel here, it may be worth waiting till ember-cli-typescript 2 is out of beta: at that point you won’t need to use the internals, and things will Just Work™. No worries either way; it was just the one bit that caught my attention on first skim.

(We don’t have a definite timeline for that, but I’m going to publish a blog post about it to get some more eyes on it; initial signs including from our largest app are very good.)

@dfreeman
Copy link
Contributor

dfreeman commented Nov 1, 2018

The need for the move-declaration-files script isn't something we have a good answer for yet (in 1.x or the 2.x betas), though it's something I've been thinking about trying to address soon, as TypeScript is a good fit for lots of testing-oriented addons, but those addons also have a tendency to do things with path remapping.

I think there's a good chance we can look at the paths in tsconfig.json to be more intelligent about where we move declarations prior to publish, rather than baking in knowledge of "normal" addon layout. That would allow us to make sure all the @ember/test-helpers declarations are in the right place automatically.

@Turbo87
Copy link
Member Author

Turbo87 commented Nov 1, 2018

@rwjblue I've trimmed this down to the most important commits, and I think it's good to go. I got several follow-up changes lined up already and will open PRs for them once this one is merged.

@Turbo87 Turbo87 changed the title WIP: Convert to TypeScript Convert to TypeScript Nov 1, 2018
@@ -158,8 +162,8 @@ export function getSettledState() {
let pendingRequestCount = pendingRequests();

return {
hasPendingTimers: Boolean(run.hasScheduledTimers()),
hasRunLoop: Boolean(run.currentRunLoop),
hasPendingTimers: Boolean((run as any).hasScheduledTimers()),
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't Ember.run have stuff in @types/ember? Why do we have to cast here?

Copy link
Member Author

Choose a reason for hiding this comment

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

it does, but unfortunately those two are missing from the published types 😢

Copy link

@mike-north mike-north Nov 1, 2018

Choose a reason for hiding this comment

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

@Turbo87 @rwjblue The only reason they're missing is because there's no indication that they're part of Ember's public API. We look to https://www.emberjs.com/api/ as the source of truth.

Copy link
Member

Choose a reason for hiding this comment

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

Ya, seems fine though this library (IMHO by necessity) will have to use what amount to private APIs for applications so that it can absorb any private API churn and expose actually public stable APIs to our users.

Copy link

@mike-north mike-north Nov 1, 2018

Choose a reason for hiding this comment

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

Ya, seems fine though this library (IMHO by necessity) will have to use what amount to private APIs for applications so that it can absorb any private API churn and expose actually public stable APIs to our users.

In the future, we may want to discuss the pros/cons of publishing an additional types package for authors of libraries like this, to layer on top of the public ember types. I have some quality/stability concerns around each author aiming to define/maintain this type info themselves.

Currently, this is often thought of as a (false) choice between type-checking and keeping to the confines of the public API.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah. The issue is somewhat complex, the layers of “public” are quite different. For example:

  • intended for consumption by apps
  • intended for consumption by tooling
  • intended for consumption by “privileged” addons

Things like the modifier and component manager APIs are good examples of things intended for addons but not apps.

Things like default outlet templates / using outlet state / etc are examples of things Ember intentionally exposes for this addon to be able to provide its APIs, but those things should never be made exposed to other addons or apps...

Copy link
Contributor

Choose a reason for hiding this comment

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

This is highly motivating me to get back to the work I started in the spring: we really need an RFC clarifying a lot of this. (And quite a few other things around types and stability, too.) That's going to become increasingly important as more and more of core pieces of Ember land. I'll see if I can block out some time to do that in the next two weeks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Addendum: as a stopgap I think publishing something like an "intimate APIs" with LOUD caveats about what they do and don't represent, and of course not installing them by default from ember-cli-typescript, would probably work for the short-to-medium term fix we need to prevent the problem we're going to start seeing (if we're not already) of multiple, differing type definitions for the same information.

@rwjblue rwjblue merged commit c149e0b into emberjs:master Nov 1, 2018
@Turbo87 Turbo87 deleted the ts branch November 1, 2018 22:33
@jamescdavis
Copy link

This is a great start! I was going to comment on places where the types could be tightened up, but I see you're already on it in #452.

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

Successfully merging this pull request may close these issues.

6 participants