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

[Bug] undefined is required in a route's serialize method in the stable types #20487

Closed
boris-petrov opened this issue Jun 29, 2023 · 3 comments · Fixed by #20490
Closed

[Bug] undefined is required in a route's serialize method in the stable types #20487

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

Comments

@boris-petrov
Copy link
Contributor

🐞 Describe the Bug

Check the repro.

app/routes/foo.ts:8:19 - error TS2416: Property 'serialize' in type 'FooRoute<T>' is not assignable to the same property in base type 'Route<T>'.
  Type '(object: Child) => any' is not assignable to type '(model: T | undefined, params: string[]) => { [key: string]: unknown; } | undefined'.
    Types of parameters 'object' and 'model' are incompatible.
      Type 'T | undefined' is not assignable to type 'Child'.
        Type 'undefined' is not assignable to type 'Model'.

8   public override serialize(object: Child): any {
                    ~~~~~~~~~

🔬 Minimal Reproduction

Repo.

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

😕 Actual Behavior

Type error on serialize.

🤔 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

I have a fix for this at #20490, including a type test to make sure it does not regress. Note that the differences there are on purpose – your example code is actually invalid even with the fix, because the class cannot assume Child as the param, only T.

@boris-petrov
Copy link
Contributor Author

Note that the differences there are on purpose – your example code is actually invalid even with the fix, because the class cannot assume Child as the param, only T.

Actually, it does compile with the fix (you can check by reverting the last commit). Which is rather strange, you're right, but I guess due to co/contravariance?

@chriskrycho
Copy link
Contributor

At least in the context of the type tests I wrote, it does not type check. It's possible that the preview types themselves had a bug here which were allowing it!

@chriskrycho chriskrycho added Bug TypeScript Work on Ember’s types labels Jun 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