stamp icon indicating copy to clipboard operation
stamp copied to clipboard

Typescript support for `@stamp/xxx` packages.

Open PopGoesTheWza opened this issue 6 years ago • 4 comments

In order to offer users proper Typescript support, two options are available:

  1. hand crafted .d.ts files for each published package
  2. porting current .js source code to Typescript (with incremental build and automatic generation of source maps and .d.ts files

First option might be faster but implies to maintain .js source and .d.ts in sync as code base evolve.

Second option would take longer to achieve but should be easier to maintain in the long run. Caveats is that source code no longer is JavaScript but Typescript. Final code being transpiled (using Typescript or Babel) thus making fine control of the code (slightly) less possible. On the other hand, source Typescript code can benefit from the latest ESnext syntax while still producing JavaScript code compatible with the minimal supported version(es5, es2015, etc.)

PopGoesTheWza avatar Nov 04 '19 22:11 PopGoesTheWza

Yeah! This package is a great target to be ported to TS! :) That would be amazing. :) Feel free to do it. Also, I believe that rewriting it with TS is actually faster than adding .d.ts files. :)

koresar avatar Nov 04 '19 22:11 koresar

I'll start a Typescript branch after most of the other issues are cleared:

  • CI Travis no longer shouting
  • Node/es version support
  • ESlint+Prettier linting

PopGoesTheWza avatar Nov 04 '19 23:11 PopGoesTheWza

A bit of a hack, but I've found that this works in package.json to provide types to @stamp/it:

{
  "dependencies: {
    "@stamp/it": "^1.1.0"
  },
  "devDependencies": {
    "@types/stampit": "^4.3.1",
    "@types/stamp__it": "./node_modules/@types/stampit"
  }
}

sambauers avatar Jul 21 '21 04:07 sambauers

Or new and more elegant notation:

{
  "dependencies": {
    "@stamp/it": "=1.1.0",
    "@types/stamp__it": "npm:@types/stampit@=4.3.2"
}

NOTE: I believe @types/stamp__it needs to be a dependency and not a devDependency in cases when the code that uses @stam/it + @types/stampit is packages a library and published on npmjs.com.

char0n avatar Feb 04 '23 21:02 char0n