-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check property names during instantiation (#94)
* fix: require-passing-this * fix: check property name * chore: delete unwanted diffs * docs: add jsDoc
- Loading branch information
1 parent
33583e1
commit 4143df2
Showing
9 changed files
with
94 additions
and
2 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
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
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
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
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,20 @@ | ||
import { isClassDeclaration, isConstructorDeclaration, Type } from "typescript"; | ||
|
||
/** | ||
* Parses type to get the property names of the class constructor. | ||
* @returns The property names of the class constructor. | ||
*/ | ||
export const getConstructorPropertyNames = (type: Type): string[] => { | ||
const declarations = type.symbol?.declarations; | ||
if (!declarations?.length) return []; | ||
|
||
const classDeclaration = declarations[0]; | ||
if (!isClassDeclaration(classDeclaration)) return []; | ||
|
||
const constructor = classDeclaration.members.find((member) => | ||
isConstructorDeclaration(member) | ||
); | ||
if (!constructor?.parameters.length) return []; | ||
|
||
return constructor.parameters.map((param) => param.name.getText()); | ||
}; |