stampit-org / stampit

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

Not so much an issue but a question. #354

Open KookiKodes opened 3 years ago

KookiKodes commented 3 years ago

How do you use typescript with these composable functions, like how should I compose the interface so that I can get proper static types. IE stamp<SomeInterface>({}) Thank you ahead of time :) ! I ask this because anytime I use Stamp.somestaticproperty. I get an error stating that the property does not exist.

koresar commented 3 years ago

:( I'm so sad seeing TS poor support.

There is a great effort by @PopGoesTheWza to rewrite @stamp/it using TS: https://github.com/stampit-org/stamp/pull/78 Maybe he has some suggestions?

sammys commented 3 years ago

@KookiKodes Besides what @PopGoesTheWza is working on, this project (stampit) does have a @types/stampit package available that will bring some useful types into play. Something like this worked for me... note that it's from memory... I didn't compile or run it:

import stampit from 'stampit';

interface IFoo {
    name: string;
}

const Foo = stampit<IFoo>({
    properties: {
        name: undefined,
    },
});

function getFoo(): stampit.Stamp<IFoo> {
    return Foo();
}

@koresar I'll take a look at stampit-org/stamp#78 to get up to speed.

KookiKodes commented 3 years ago

I did notice the @types/stampit package and greatly appreciate the project as a whole. I will definitely try around to see if I can get the statics portion working. Thank you both for the quick replies :) ! I'll keep you updated!

PopGoesTheWza commented 3 years ago

I need about a couple full days to complete the current PR for @stamp/* support... But free time is scarce at the moment.