Skip to content

unexpected behavior when use union type #28860

Closed
@MaoScut

Description

@MaoScut

TypeScript Version: 3.1.4

Search Terms:
union type
Code

export type basetype = {
  id: string;
}
export type supertype1 = basetype & {}
export type supertype2 = basetype & {
  key1: any;
  key2: any;
}

function myfun(p: supertype2 | supertype1) {
  return 
}

myfun( {
  id: '',
  key1: '',
})

Expected behavior:
{
id: '',
key1: '',
} is not supertype1 or supertype2, when it is used to be a parameter of myfun, typescript should report an error.
Actual behavior:
there is no error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions