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

init in classic components takes an argument in the stable types #20483

Open
boris-petrov opened this issue Jun 29, 2023 · 4 comments · Fixed by #20492
Open

init in classic components takes an argument in the stable types #20483

boris-petrov opened this issue Jun 29, 2023 · 4 comments · Fixed by #20492
Labels
Bug TypeScript Work on Ember’s types

Comments

@boris-petrov
Copy link
Contributor

boris-petrov commented Jun 29, 2023

🐞 Describe the Bug

init in classic components used to not accept any arguments and super.init() could be called like that. Since 5.1.0, this no longer works. I believe this is a bug.

app/components/foo-component.ts:5:11 - error TS2554: Expected 1 arguments, but got 0.

5     super.init();
            ~~~~~~

  node_modules/ember-source/types/stable/@ember/-internals/glimmer/lib/component.d.ts:786:10
    786     init(properties: object | undefined): void;
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    An argument for 'properties' was not provided.

🔬 Minimal Reproduction

Repo.

Run npm install and then ./node_modules/.bin/tsc.

😕 Actual Behavior

Type error on super.init().

🤔 Expected Behavior

No error. Removing the last commit (which upgrades Ember) and rerunning npm install and then tsc will remove the errors.

🌍 Environment

  • Ember: 5.1.0
  • Node.js/npm: 20.3.1/9.7.2
  • OS: Linux
  • Browser: N/A

cc @chriskrycho

@chriskrycho
Copy link
Contributor

Whoops, this one is quite straightforward and I missed it while doing the work for 5.1.1. Should be fixed by #20492.

@boris-petrov
Copy link
Contributor Author

Thanks for the release! However, even with 5.1.2 I get the same error. The init method comes from node_modules/ember-source/types/stable/@ember/object/core.d.ts:114. There is a comment on that noting:

NOTE: If you do override `init` for a framework class like `Component`
from `@ember/component`, be sure to call `this._super(...arguments)`
in your `init` declaration!
If you don't, Ember may not have an opportunity to
do important setup work, and you'll see strange behavior in your
application.

So I'm not sure whether we really need to pass ...arguments or not... I was under the impression that this is not needed? Is this some old comment or it's still true?

@boris-petrov
Copy link
Contributor Author

boris-petrov commented Jul 3, 2023

I pushed another commit to the reproduction repo. It simply does:

import Controller from '@ember/controller';

export default class ApplicationController extends Controller {
  public override init(): void {
    super.init();
  }
}

That causes an error. That is, super.init() in components now works fine but in controllers (and routes, and services, and classes that simply extend EmberObject) doesn't. The error is:

app/controllers/application.ts:5:11 - error TS2554: Expected 1 arguments, but got 0.

5     super.init();
            ~~~~~~

  node_modules/ember-source/types/stable/@ember/object/core.d.ts:114:10
    114     init(_properties: object | undefined): void;
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    An argument for '_properties' was not provided.

@chriskrycho chriskrycho reopened this Jul 31, 2023
@chriskrycho
Copy link
Contributor

Will take a gander sometime this week or next to try to get this resolved. Thanks for the follow-up!

@kategengler kategengler changed the title [Bug] init in classic components takes an argument in the stable types init in classic components takes an argument in the stable types Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug TypeScript Work on Ember’s types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants