Skip to content

feat(gatsby-image): export TS interfaces of gatsby-image object types#14284

Merged
pieh merged 1 commit intomasterfrom
export-image-types
May 24, 2019
Merged

feat(gatsby-image): export TS interfaces of gatsby-image object types#14284
pieh merged 1 commit intomasterfrom
export-image-types

Conversation

@kripod
Copy link
Copy Markdown
Contributor

@kripod kripod commented May 23, 2019

Description

When passing optimized images through type-safe components, the need for using gatsby-image object types may emerge.

E.g.:

import Img, { FixedObject } from 'gatsby-image';

type UserProps = {
  avatar: FixedObject;
  // ...
};

export default function User({ avatar }: UserProps) {
  return (
    <div>
      <Img fixed={avatar} />
      {/* ... */}
    </div>
  );
}

@pieh pieh changed the title Export interfaces of gatsby-image object types feat(gatsby-image): export interfaces of gatsby-image object types May 24, 2019
@pieh pieh changed the title feat(gatsby-image): export interfaces of gatsby-image object types feat(gatsby-image): export TS interfaces of gatsby-image object types May 24, 2019
Copy link
Copy Markdown
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable, thanks @kripod!

@pieh pieh merged commit b3e306c into master May 24, 2019
@pieh pieh deleted the export-image-types branch May 24, 2019 13:12
@joealden
Copy link
Copy Markdown

@kripod could you please explain to me why these need to be exported? I have been using these interfaces for a long time now without problems (when they weren't marked as exported). I can't find anything in the TypeScript docs on declaration files about this, so I wondered if you know why this is allowed?

To get a better understanding of what I mean, here is a screenshot of the named imports available to me with gatsby-image 2.1.1 (the version that contains this PR's commits):

screenshot

As you can see, I can import and use the GatsbyImageProps interface in my own code, and as the file currently exists, this interface isn't marked as exported. This is what it was like for me previously in gatsby-image in relation to the FixedObject and FluidObject interfaces.

The only reason I can think this would have ever worked is because maybe TypeScript treats index.d.ts files specially? Maybe they export everything in them by default or something? I am just guessing though, as like I said, I can't find any documentation that suggests this is the case.

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

Successfully merging this pull request may close these issues.

3 participants