stampit-org / stampit

OOP is better with stamps: Composable object factories.
https://stampit.js.org
MIT License
3.02k stars 102 forks source link

Typescript support #348

Closed PopGoesTheWza closed 4 years ago

PopGoesTheWza commented 4 years ago

Issue #245 [Work In Progress]

A more advanced version of stampit types

There is a "DefinitelyTyped" style tests.ts file which illustrate basic stampit usage under typescript.

koresar commented 4 years ago

Is it still WIP?

PopGoesTheWza commented 4 years ago

Currently awaiting review and proposal for testing.

koresar commented 4 years ago

@PopGoesTheWza I've sent an invite to you to join the stampit-org collaborators. Now you can clone https://github.com/stampit-org/stampit.git repo and push straight to it. So, in the future if you are creating any more PRs I'd recommend creating a branch in this stampit-org/stampit repo instead of your own fork.

PopGoesTheWza commented 4 years ago

@koresar holding on committing types tests as I run into an issue with latest version of dtslint

koresar commented 4 years ago

Tell me when it's ready to merge. :) Or merge yourself when you think it's ready to go. I'll publish.

PopGoesTheWza commented 4 years ago

@koresar We could merge it right now with the following implications:

koresar commented 4 years ago

Sounds good to me! Go ahead. Merge it. I'll do release notes after that.

Do you believe it better be realised as v4.4 or v4.3.1?

On Wed., 30 Oct. 2019, 23:00 PopGoesTheWza, notifications@github.com wrote:

@koresar https://github.com/koresar We could merge it right now with the following implications:

  • the DT @types/stampit would become obsolete (i.e. only useful when using version of stampit prior 4.3
  • no unit tests for types at the moment (I have a test suite "à la" DT ready but it require an update of the dtslint package.)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stampit-org/stampit/pull/348?email_source=notifications&email_token=AAMMEL2JRAHNGFFLH5XKMQDQRFZNXA5CNFSM4JBMW742YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECT4X5Y#issuecomment-547867639, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMMELYQOWKUHMPTDC2KIBDQRFZNXANCNFSM4JBMW74Q .

PopGoesTheWza commented 4 years ago

4.4 I'd say. Sample TS might be necessary?

koresar commented 4 years ago

Sorry, what's "Sample TS"? And where this needs to be better put?

PopGoesTheWza commented 4 years ago

I meant sample typescript code. It could be some doc/typescript.md file, a wiki entry, a fun with stamp post. Your pick.

koresar commented 4 years ago

Do whatever you think is the best for the community and easiest for you.

I'd recommend going for:

Take into account, that my time is quite limited currently as I have 23 days old baby. :)

koresar commented 4 years ago

I need to send you an invite link to the stampit.js.org docs editor. Please DM me in twitter (kore_sar) or email kore.sar on gmail.

koresar commented 4 years ago

Released as v4.3.1 🎉

https://github.com/stampit-org/stampit/releases/tag/v4.3.1

char0n commented 3 years ago

Hi guys,

I have question regarding Typescript usage of stamps.

interface Type {
  prop: string;
}

const Type: stampit.Stamp<Type> = stampit({ 
  statics: {
    of(value) {
      return Type({ prop: value });
    }
  },
  props: {
    prop: ''
  },
  init({ prop }) {
    this.prop = prop;
  }
});

Type.of(1); // Property of doesn't exist on type Stamp

Not sure If what I'm doing is correct and have no idea how to properly use static of function for the Type stamp. I didn't find any documentation on TypeScript + Stamps. Could you guys clarify please?

koresar commented 3 years ago

Your usage is correct if done with JavaScript. TypeScript support is lagging behind. There was a great push a year ago. But it was not finished. Unfortunately.

I'd recommend any at this stage.

Rant: TypeScript has the same mistake as many other languages - it uses classes and inheritance. The stamps were invented specifically to overcome the limitations of classes (hence you have the error). Bridging two together is possible, but very very hard due to TS design.

char0n commented 3 years ago

@koresar thanks