Generate type definitions at build time#4
Generate type definitions at build time#4sakai-akinobu wants to merge 10 commits intoHearthSim:mainfrom
Conversation
`yarn add --dev rollup-plugin-typescript2`
`yarn upgrade rollup@^0.68.2`
`yarn remove rollup-plugin-typescript`
| /dist/ | ||
| node_modules/ | ||
| npm-debug.log | ||
| /.rpt2_cache |
There was a problem hiding this comment.
This is to ignore the cache directory generated by rollup-plugin-typescript2.
https://github.com/ezolenko/rollup-plugin-typescript2#plugin-options
| "mocha": "^5.0.0", | ||
| "prettier": "^1.10.2", | ||
| "rollup": "^0.55.1", | ||
| "rollup": "^0.68.2", |
There was a problem hiding this comment.
This is the requirement of rollup-plugin-typescript2.
https://github.com/ezolenko/rollup-plugin-typescript2#requirements
| "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.
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
| /* 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.
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 😄 |
| // "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.
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
FormatTypeas 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.