Skip to content

Callable types are not validated properly #40270

Closed
@karlismelderis

Description

@karlismelderis

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdFix AvailableA PR has been opened for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions