codemix / babel-plugin-typecheck

Static and runtime type checking for JavaScript in the form of a Babel plugin.
MIT License
886 stars 44 forks source link

Error message does not describe expected type signature when using type aliases #136

Closed gajus closed 7 years ago

gajus commented 8 years ago

Code:

type TypeAdCampaign = {
    movieId: number,
    language: string,
    initialState: ?('collapsed' | 'expanded'),
    latitude: ?string,
    longitude: ?string
};

export default (adCampaign: TypeAdCampaign = {}) => {
    // ...
};

Error:

Uncaught TypeError: Value of argument "adCampaign" violates contract.

Expected:
TypeAdCampaign

Got:
{
  movieId: string;
  movieName: string;
  language: string;
}

Expected error:

Uncaught TypeError: Value of argument "adCampaign" violates contract.

Expected:
TypeAdCampaign
{
    movieId: number,
    language: string,
    initialState: ?('collapsed' | 'expanded'),
    latitude: ?string,
    longitude: ?string
}

Got:
{
  movieId: string;
  movieName: string;
  language: string;
}
phpnode commented 8 years ago

I think this was recently introduced because babel removed support for caching paths on nodes. I'd definitely like to get this back in.