Skip to content

The actual type of the function return value is inconsistent with the expected type #44221

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

Closed
lppking opened this issue May 23, 2021 · 1 comment

Comments

@lppking
Copy link

lppking commented May 23, 2021

Bug Report

πŸ”Ž Search Terms

spread operator, incorrect type check information,

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about TS4.2.3

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface ListItem {
  name: string
  age: number
}

function test(): ListItem[] {
  const a = [{
    name: "name",
    age: 18
  }]
  return {
    ...a
  }
}

πŸ™ Actual behavior

  • First of all, the expected return value type is an array, but there is no error message when returning an object
  • Secondly, TypeScript seems to have an array attribute on the return value of the test function, which is a bit abnormal

πŸ™‚ Expected behavior

I hope that the type information can be matched correctly, and the corresponding type error message will be given,thanks

@jcalz
Copy link
Contributor

jcalz commented May 23, 2021

Looks like a duplicate of #35778.

@lppking lppking closed this as completed May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants