Skip to content

Commit

Permalink
fix Constructor problem (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Nov 22, 2021
1 parent 3909645 commit bcd6dc5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clone-class",
"version": "1.0.3",
"version": "1.1.0",
"description": "Clone an ES6 Class as Another Class Name for Isolating Class Static Properties.",
"type": "module",
"exports": {
Expand Down Expand Up @@ -44,14 +44,14 @@
},
"homepage": "https://github.com/huan/clone-class#readme",
"devDependencies": {
"@chatie/eslint-config": "^0.16.2",
"@chatie/eslint-config": "^1.0.4",
"@chatie/git-scripts": "^0.6.2",
"@chatie/tsconfig": "^0.20.2",
"@chatie/tsconfig": "^4.5.3",
"cross-env": "^7.0.3",
"file-box": "^0.19.5",
"file-box": "^1.4.3",
"npm-run-all": "^4.1.5",
"shx": "^0.3.3",
"tstest": "^0.7.3"
"tstest": "^1.0.1"
},
"publishConfig": {
"access": "public",
Expand Down
6 changes: 2 additions & 4 deletions src/constructor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@ test('Constructor<T> with private constructor class', async t => {
* Huan(202110): TypeError: Cannot read property 'valueDeclaration' of undefined #58
* https://github.com/huan/clone-class/issues/58
*/
test.skip('class with static methods', async t => {
test('class with static methods', async t => {
class StaticMethodClass {

static staticMethod () {}
protected constructor () {}

}

// const C: typeof StaticMethodClass = StaticMethodClass as any as Constructor<StaticMethodClass, typeof StaticMethodClass>
const C: typeof StaticMethodClass = StaticMethodClass as any as Constructor<StaticMethodClass> as any

const C: typeof StaticMethodClass = StaticMethodClass as any as Constructor<StaticMethodClass, typeof StaticMethodClass>
t.ok(C, 'should be ok')
})

Expand Down
29 changes: 7 additions & 22 deletions src/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
* - Types for classes as values in TypeScript
* https://2ality.com/2020/04/classes-as-values-typescript.html
*/
/**
* Huan(202108) version:
*
* T: the `Class`
* P: `typeof Class`
*/

export type ClassInterface<C> = {
[key in keyof C]: C[key];
Expand All @@ -30,25 +24,16 @@ type InstanceInterface <I> = {
prototype: I
}

type Constructor<I extends {} = {}> = InstanceInterface<I>

/**
* Huan(202110): TypeError: Cannot read property 'valueDeclaration' of undefined #58
* https://github.com/huan/clone-class/issues/58
* Huan(202108) version:
*
* - Update Oct 13: `typescript@4.5.0-beta` not fix
*/
// type Constructor<I extends {} = {}, C = any> = ClassInterface<C> & InstanceInterface<I>

// type Constructor<T extends Object> = {
// new (...args: any[]): T
// prototype: T
// }

/**
* Huan(202109) versino:
* T: the `Class`
* P: `typeof Class`
*/
// type Constructor<T> = Function & { prototype: T }
type Constructor<
I extends {} = {},
C = {}
> = ClassInterface<C> & InstanceInterface<I>

/**
* https://github.com/wechaty/wechaty/issues/2090
Expand Down

0 comments on commit bcd6dc5

Please sign in to comment.