Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript support #52

Closed
tkrotoff opened this issue Sep 21, 2019 · 7 comments
Closed

Add TypeScript support #52

tkrotoff opened this issue Sep 21, 2019 · 7 comments

Comments

@tkrotoff
Copy link

tkrotoff commented Sep 21, 2019

Current type definition I use in my projects (something like types/html-webpack-tags-plugin.d.ts):

declare module 'html-webpack-tags-plugin' {
  import { Plugin } from 'webpack';

  interface Options {
    append?: boolean;
    prependExternals?: boolean;
    jsExtensions?: string | string[];
    cssExtensions?: string | string[];
    useHash?: boolean;
    addHash?: (assetPath: string, hash: string) => string;
    hash?: boolean | Function;
    usePublicPath?: boolean;
    addPublicPath?: (assetPath: string, publicPath: string) => string;
    publicPath?: boolean | string | Function;

    tags?: string | object | Array<string | object>;
    links?: string | object | Array<string | object>;
    scripts?: string | object | Array<string | object>;
    metas?: string | object | Array<string | object>;
  }

  export default class HtmlWebpackTagsPlugin extends Plugin {
    constructor(options: Options);
  }
}

Then you have autocompletion using vscode or whatever smart editor/IDE:

// webpack.config.ts
import HtmlWebpackTagsPlugin from 'html-webpack-tags-plugin';

...
new HtmlWebpackTagsPlugin({...});
...

3 solutions (see https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html):

@jharris4
Copy link
Owner

Can you elaborate on what this means? Are you just looking for TypeScript types?

If so, a PR would be welcome...

@jharris4
Copy link
Owner

Ok, I’m new to TypeScript but I’m curious.

Thanks for sharing your starter definition, I’ll see if I can find time to get around to adding it next week.

@jharris4
Copy link
Owner

I've added the TypeScript definitions and released in 2.0.16.

@tkrotoff Can you please try out the definitions in the new version and let me know if it works for you so I can close this issue? Thanks!

@tkrotoff
Copy link
Author

File types.d.ts is not part of the package: https://unpkg.com/browse/html-webpack-tags-plugin@2.0.16/

I guess you have to add types.d.ts to files inside package.json: https://docs.npmjs.com/files/package.json#files

  ...
  "files": [
    "index.js",
    "types.d.ts"
  ],
  ...

@jharris4
Copy link
Owner

Oh crap! yeah I only tested locally with import HtmlWebpackTagsPlugin from "../typings.d.ts";

I'll publish another version with the file added. Sorry about that, and thanks for reporting it!

@jharris4
Copy link
Owner

Published in 2.0.17. That should do the trick.

@tkrotoff
Copy link
Author

It works fine, thx!

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

No branches or pull requests

2 participants