-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support constructor node types (#1512)
- Loading branch information
Showing
5 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import ts from "typescript"; | ||
import { SubNodeParser } from "../SubNodeParser"; | ||
import { BaseType } from "../Type/BaseType"; | ||
import { ConstructorType } from "../Type/ConstructorType"; | ||
|
||
/** | ||
* A constructor node parser that creates a constructor type so that mapped | ||
* types can use constructors as values. There is no formatter for constructor | ||
* types. | ||
*/ | ||
export class ConstructorNodeParser implements SubNodeParser { | ||
public supportsNode(node: ts.ConstructorTypeNode): boolean { | ||
return node.kind === ts.SyntaxKind.ConstructorType; | ||
} | ||
public createType(): BaseType { | ||
return new ConstructorType(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { BaseType } from "./BaseType"; | ||
|
||
export class ConstructorType extends BaseType { | ||
public getId(): string { | ||
return "constructor"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type MyConstructor = new () => any; | ||
|
||
export type MyType = { | ||
a: MyConstructor; | ||
}; |