Skip to content

Callable types are not validated properly #40270

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
karlismelderis opened this issue Aug 26, 2020 · 2 comments
Closed

Callable types are not validated properly #40270

karlismelderis opened this issue Aug 26, 2020 · 2 comments
Labels
Duplicate An existing issue was already created Fix Available A PR has been opened for this issue

Comments

@karlismelderis
Copy link

karlismelderis commented Aug 26, 2020

TypeScript Version: 4.0.2

Search Terms:
callable

Code

type Retrieve = () => {
  extracted?: string
  raw: string
}

const retrieve: Retrieve = () => {
  return {
    raw: 'mhm',
    extracted: 'aha',
    a: 1, // no error for this extra prop
  }
}

interface RetrieveInterface {
  (): {
  extracted?: string
  raw: string
}
}

const retrieveInterface: RetrieveInterface = () => {
  return {
    raw: 'mhm',
    extracted: 'aha',
    a: 1, // no error for this extra prop
  }
}

Expected behavior:
get same error as setting return type to arrow function

const retrieve = (): {
  extracted?: string
  raw: string
} => {
  return {
    raw: 'mhm',
    extracted: 'aha',
    a: 1,
  }
}

Actual behavior:
no error

Playground Link:
https://www.typescriptlang.org/play?#code/C4TwDgpgBAShwCcCWEBu0C8UAUBKKGAfFAN4BQUUEAHogIYDGwEAJgPwBcUAzokgHYBzClAR0A7l17IhZAL5kyDAPb9eo+MjQQucPtoI5cXAsXKUE8AK4J+pERYlcA5AFsAFq+cAaB1VpiTKwudO50Pn50XACMvpQKCmQCzAgAZozQelroAJL8KekM0OZGXCU09EHsUnyyjpI8tcIJiipqwBr6ufkQaRm6mijdBRmGeKb2Fta2k5SiTlBunhFz-pXMLCFhK3NRULEiLUqq6pZdEACiCAjKCGPGsxWBG5yNMsL1Ne-yEyVnNnYSp9Fh4vHE5k9GBstuFwZQ9gd4vIgA

Related Issues:
Maybe I hit same as on going discussion here -> #241

@DanielRosenwasser
Copy link
Member

Duplicate of #241, but I have a potential fix. Check out #40311 (comment)

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Sep 2, 2020
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Sep 2, 2020
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants