-
Notifications
You must be signed in to change notification settings - Fork 11
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
Generate type definitions at build time #4
base: main
Are you sure you want to change the base?
Generate type definitions at build time #4
Conversation
`yarn add --dev rollup-plugin-typescript2`
`yarn upgrade rollup@^0.68.2`
`yarn remove rollup-plugin-typescript`
@@ -1,3 +1,4 @@ | |||
/dist/ | |||
node_modules/ | |||
npm-debug.log | |||
/.rpt2_cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to ignore the cache directory generated by rollup-plugin-typescript2.
https://github.com/ezolenko/rollup-plugin-typescript2#plugin-options
@@ -42,12 +42,12 @@ | |||
"karma-rollup-preprocessor": "^5.1.1", | |||
"mocha": "^5.0.0", | |||
"prettier": "^1.10.2", | |||
"rollup": "^0.55.1", | |||
"rollup": "^0.68.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the requirement of rollup-plugin-typescript2.
https://github.com/ezolenko/rollup-plugin-typescript2#requirements
"rollup-plugin-babel": "^3.0.3", | ||
"rollup-plugin-commonjs": "^8.3.0", | ||
"rollup-plugin-jscc": "^0.3.3", | ||
"rollup-plugin-node-resolve": "^3.0.2", | ||
"rollup-plugin-typescript": "^0.8.1", | ||
"rollup-plugin-typescript2": "^0.19.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since rollup-plugin-typescript seems to be unable to generate type definitions, I used rollup-plugin-typescript2.
https://github.com/rollup/rollup-plugin-typescript/issues/54
@@ -2,12 +2,12 @@ | |||
"compilerOptions": { | |||
/* Basic Options */ | |||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ | |||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | |||
"module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the requirement of rollup-plugin-typescript2.
https://github.com/ezolenko/rollup-plugin-typescript2#some-compiler-options-have-more-than-one-compatible-value
Hi there, thank you for your pull request! We require a CLA to be signed for contributions to this (and other) repositories. We capture this using a private GitHub repository. I have sent you an invite, and the README on that repository contains instructions on how to proceed. Let me know if you have any questions. |
I signed it 😄 |
// "lib": [], /* Specify library files to be included in the compilation. */ | ||
// "allowJs": true, /* Allow javascript files to be compiled. */ | ||
// "checkJs": true, /* Report errors in .js files. */ | ||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ | ||
// "declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
"declaration": true, /* Generates corresponding '.d.ts' file. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using this option, the following files are generated under the dist
directory, and these will be included when distributing as npm package.
- base64.d.ts
- buffer.d.ts
- constants.d.ts
- index.d.ts
For example, index.d.ts
has the following contents.
import { DeckDefinition, DeckList } from "../types";
import { FormatType } from "./constants";
export declare function encode(deck: DeckDefinition): string;
export declare function decode(deckstring: string): DeckDefinition;
export { FormatType, DeckDefinition, DeckList };
https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
66afeb6
to
7110a88
Compare
c8c91c0
to
72c9ca7
Compare
Thank you for a nice module! Hearthstone is a nice game, isn't it?
I use this module with TypeScript, but it seems that it can not use
FormatType
as a value.On the other hand, when using it with JavaScript it was able to be used correctly.
I guess this is because the type definition does not match the contents of the actual module.
To solve this problem, I fixed to generate type definitions at build time. By doing so, we can handle it properly from TypeScript as well.