react-meta-tags icon indicating copy to clipboard operation
react-meta-tags copied to clipboard

MetaTags in TypeScript

Open ludwich opened this issue 6 years ago • 8 comments

How do i implement this in .net core with typescript ? i cant import since it has an any type and if i require it it only gives me an error that is does not have a call signature or construct.

ludwich avatar Mar 11 '18 10:03 ludwich

You can just explicitly cast it as any or declare the module in override.d.ts

dahvinchee avatar Jul 16 '18 14:07 dahvinchee

I don't know why it is not included in the repo itself.

create a file "react-meta-tags.d.ts" and paste the below content.

// Type definitions for react-meta-tags 0.7.4
// Project: react-meta-tags
// Definitions by: Siraj Alam https://github.com/sirajalam049

declare module "react-meta-tags" {
    export default class Meta extends React.Component { }
}

sirajalam049 avatar Oct 18 '19 18:10 sirajalam049

This does work, but it's not ok to ask people to put your username in the file just for answering. 😒

doublejosh avatar Jan 30 '20 00:01 doublejosh

@doublejosh haha, funny you mentioned it. The snippet I gave above is pasted from the file I created, using. TypeScript types definition template

sirajalam049 avatar Feb 12 '20 18:02 sirajalam049

OK, you can put your name in your files if you want, but it's weirdly self-promotional to instruct people to do so.

doublejosh avatar Feb 24 '20 19:02 doublejosh

Another suggested version of react-meta-tags.d.ts declaration file with more details:

interface ExtractFunctionType {
  (elements: React.ReactElement | React.ReactElement[]): void;
}

declare module "react-meta-tags" {
  export type ExtractFunction = ExtractFunctionType;

  export class MetaTagsContext extends React.Component<{
    extract: ExtractFunctionType;
  }> {};
  export class MetaTags extends React.Component {};
  export class ReactTitle extends React.Component<{ title: string }> {
  };

  export default MetaTags;
}

declare module "react-meta-tags/server" {
  export interface MetaTagsInstance {
    extract: ExtractFunctionType;
    renderToString: () => string;
    getTags: () => React.ReactElement[];
  }

  const MetaTagsServer: () => MetaTagsInstance

  export default MetaTagsServer;
}

alex-shul avatar Jan 03 '22 17:01 alex-shul

Sorry, butt IDK where to put this file in? node_modules or somewhere else, please?

tranduybau avatar Apr 14 '22 02:04 tranduybau

@trdbau You can just create a d.ts file anywhere in the folder. I would only suggest to do as global as possible, to give yourself the advantage to find it back easily.

See the image below for example, this way should work

Where to set the d ts file

yannick-coolen avatar Jun 09 '22 14:06 yannick-coolen