stampit-org / stamp

Stamps - better OOP model
https://stampit.js.org
MIT License
25 stars 3 forks source link

Typescript support for `@stamp/xxx` packages. #59

Open PopGoesTheWza opened 4 years ago

PopGoesTheWza commented 4 years ago

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.)

koresar commented 4 years ago

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. :)

PopGoesTheWza commented 4 years ago

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

sambauers commented 3 years ago

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"
  }
}
char0n commented 1 year ago

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.