mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-10 09:40:21 +08:00
Fix issue with stampit when using TS to check JavaScript (#27478)
* Fix issue with stampit when using TS to check JavaScript
**Caveat: This has not been tested within a TypeScript library.*** My knowledge of TypeScript is limited, so this has not been tested. hence, I suggest @lummish and/or @koresar review this PR.
## What it's fixing
Currently I get the following error with the vanilla stampit example below, it applies to the `const Fighter = stampit(Character(...` line and TypeScript highlights the problem across the whole function:
```sh
Expected 0-1 arguments, but got 2
```
Example taken from main stampit example.
```JavaScript
import stampit from 'stampit';
const Character = stampit({
props: {
name: null,
health: 100,
},
init({ name = this.name }) {
this.name = name;
},
});
const Fighter = stampit(Character, {
props: {
stamina: 100,
},
init({ stamina = this.stamina }) {
this.stamina = stamina;
},
methods: {
fight() {
console.log(`${this.name} takes a mighty swing!`);
this.stamina--;
},
},
});
```
* Make stampit() more generic
As discussed with @koresar.
This commit is contained in:
5
types/stampit/index.d.ts
vendored
5
types/stampit/index.d.ts
vendored
@@ -133,13 +133,16 @@ interface Options {
|
||||
composers?: Composer[];
|
||||
}
|
||||
|
||||
/** Stampit Composable for main stampit() function */
|
||||
type StampitComposable = stampit.Stamp | Descriptor | Options;
|
||||
|
||||
/**
|
||||
* Return a factory (aka Stamp) function that will produce new objects using the
|
||||
* prototypes that are passed in or composed.
|
||||
* @param options Stampit options object containing refs, methods,
|
||||
* init, props, statics, configurations, and property descriptors.
|
||||
*/
|
||||
declare function stampit(options?: Options): stampit.Stamp;
|
||||
declare function stampit(...composables: StampitComposable[]): stampit.Stamp;
|
||||
|
||||
declare namespace stampit {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user