nfl / react-helmet

A document head manager for React
MIT License
17.33k stars 659 forks source link

HelmetData interface incorrect #578

Open alrayyes opened 4 years ago

alrayyes commented 4 years ago

Do you want to request a feature or report a bug? Bug

The export interface used with Helmet.peek() is incorrect. The current interface:

export class Helmet extends React.Component<HelmetProps> {
    static peek(): HelmetData;
    static rewind(): HelmetData;
    static renderStatic(): HelmetData;
    static canUseDOM: boolean;
}

export interface HelmetData {
    base: HelmetDatum;
    bodyAttributes: HelmetHTMLBodyDatum;
    htmlAttributes: HelmetHTMLElementDatum;
    link: HelmetDatum;
    meta: HelmetDatum;
    noscript: HelmetDatum;
    script: HelmetDatum;
    style: HelmetDatum;
    title: HelmetDatum;
    titleAttributes: HelmetDatum;
}

However when using this in a mock:

const helmet = Helmet.peek()
console.log(helmet)

The following is outputted:

{
      baseTag: [],
      bodyAttributes: {},
      defer: true,
      encode: true,
      htmlAttributes: { lang: 'en' },
      linkTags: [],
      metaTags: [
        { name: 'description', content: 'passed description' },
        { property: 'og:site_name', content: 'site title' },
        { property: 'og:title', content: 'passed title' },
        { property: 'og:description', content: 'passed description' },
        { property: 'og:type', content: 'website' },
        { name: 'twitter:card', content: 'summary' },
        { name: 'twitter:creator', content: 'author' },
        { name: 'twitter:title', content: 'site title' },
        { name: 'twitter:description', content: 'passed description' }
      ],
      noscriptTags: [],
      onChangeClientState: [Function (anonymous)],
      scriptTags: [],
      styleTags: [],
      title: 'passed title | site title',
      titleAttributes: {}
    }

It appears that metaTags needs to be added to the HelmData interface.

AubreyHewes commented 3 years ago

I assume this is about the typescript types, vs library usage. The types are not (yet) maintained by this project.

See https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-helmet/

Feel free to PR the types to this lib and remove them from DefinitelyTyped

peterblazejewicz commented 3 years ago

ref: DefinitelyTyped/DefinitelyTyped#52306