Skip to content

Commit

Permalink
type inference and transformation
Browse files Browse the repository at this point in the history
type inference implemented. Now intersection types in your TypeScript code will be transformed into type guard signatures.
This functionality can help you infer type guard signatures for complex types, making your TypeScript code more expressive and maintainable.
```typescript
const inputCode = `
type IntersectionType = TypeA & TypeB;
type TypeA = { a: string };
type TypeB = { b: number };
`;
const transformedCode = transformer(inputCode);
console.log(transformedCode);
// type IntersectionType = {};
// type TypeA = { a: string };
// type TypeB = { b: number };
```
  • Loading branch information
rohit1901 authored Sep 4, 2023
2 parents 888795c + d31a137 commit 55efb0d
Show file tree
Hide file tree
Showing 21 changed files with 1,031 additions and 2,503 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
dist/
node_modules/
.idea/
.run/
coverage/
lib/
lib-esm/
Expand Down
15 changes: 15 additions & 0 deletions .run/Tests (Arrays).run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tests (Arrays)" type="JavaScriptTestRunnerJest">
<node-interpreter value="project" />
<node-options value="--experimental-vm-modules" />
<jest-package value="$PROJECT_DIR$/node_modules/jest" />
<working-dir value="$PROJECT_DIR$" />
<envs />
<scope-kind value="SUITE" />
<test-file value="$PROJECT_DIR$/src/__tests__/arrayType.spec.ts" />
<test-names>
<test-name value="Generator" />
</test-names>
<method v="2" />
</configuration>
</component>
15 changes: 15 additions & 0 deletions .run/Tests (Enums).run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tests (Enums)" type="JavaScriptTestRunnerJest">
<node-interpreter value="project" />
<node-options value="--experimental-vm-modules" />
<jest-package value="$PROJECT_DIR$/node_modules/jest" />
<working-dir value="$PROJECT_DIR$" />
<envs />
<scope-kind value="SUITE" />
<test-file value="$PROJECT_DIR$/src/__tests__/enumType.spec.ts" />
<test-names>
<test-name value="Generator" />
</test-names>
<method v="2" />
</configuration>
</component>
15 changes: 15 additions & 0 deletions .run/Tests (Generics).run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tests (Generics)" type="JavaScriptTestRunnerJest">
<node-interpreter value="project" />
<node-options value="--experimental-vm-modules" />
<jest-package value="$PROJECT_DIR$/node_modules/jest" />
<working-dir value="$PROJECT_DIR$" />
<envs />
<scope-kind value="SUITE" />
<test-file value="$PROJECT_DIR$/src/__tests__/generics.spec.ts" />
<test-names>
<test-name value="Generator" />
</test-names>
<method v="2" />
</configuration>
</component>
15 changes: 15 additions & 0 deletions .run/Tests (Interfaces).run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tests (Interfaces)" type="JavaScriptTestRunnerJest">
<node-interpreter value="project" />
<node-options value="--experimental-vm-modules" />
<jest-package value="$PROJECT_DIR$/node_modules/jest" />
<working-dir value="$PROJECT_DIR$" />
<envs />
<scope-kind value="SUITE" />
<test-file value="$PROJECT_DIR$/src/__tests__/interfaceType.spec.ts" />
<test-names>
<test-name value="Generator" />
</test-names>
<method v="2" />
</configuration>
</component>
15 changes: 15 additions & 0 deletions .run/Tests (Literal Types).run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tests (Literal Types)" type="JavaScriptTestRunnerJest">
<node-interpreter value="project" />
<node-options value="--experimental-vm-modules" />
<jest-package value="$PROJECT_DIR$/node_modules/jest" />
<working-dir value="$PROJECT_DIR$" />
<envs />
<scope-kind value="SUITE" />
<test-file value="$PROJECT_DIR$/src/__tests__/literalType.spec.ts" />
<test-names>
<test-name value="Generator" />
</test-names>
<method v="2" />
</configuration>
</component>
15 changes: 15 additions & 0 deletions .run/Tests (Utils).run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tests (Utils)" type="JavaScriptTestRunnerJest">
<node-interpreter value="project" />
<node-options value="--experimental-vm-modules" />
<jest-package value="$PROJECT_DIR$/node_modules/jest" />
<working-dir value="$PROJECT_DIR$" />
<envs />
<scope-kind value="SUITE" />
<test-file value="$PROJECT_DIR$/src/__tests__/generate.spec.ts" />
<test-names>
<test-name value="Utils" />
</test-names>
<method v="2" />
</configuration>
</component>
12 changes: 12 additions & 0 deletions .run/start-dev.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="start-dev" type="js.build_tools.npm" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="start-dev" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>
12 changes: 12 additions & 0 deletions .run/test.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="test" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="test" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>
12 changes: 12 additions & 0 deletions .run/watch-mode.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="watch-mode" type="js.build_tools.npm" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="watch-mode" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

## 1.0.10 - 2023-08-25
## 2.0.0 - 2023-09-04

### Commits

- Merge 83757a9f61047ad69838ea1f8790ffcf158c150b into 61df43c665a3150b6b98f4d1a9e62330a5840d57 [`306349d`](https://github.com/rohit1901/ts-gen-typeguards/commit/306349d67719feb2ec3920c870cce9d68cc337c6)
- Merge bb112976f5e3c2216dffef06a5dd1aec0edc945c into 888795c6c6e1d29b36ec9fe479132426269659cf [`5456e63`](https://github.com/rohit1901/ts-gen-typeguards/commit/5456e6320652084cf5299ae53f157eb34958f2cc)
3 changes: 1 addition & 2 deletions input/combinedTypeGuards.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Generated using ts-gen-typeguards
// @ts-nocheck
// Numeric enum
export enum DirectionEnum {
Up = 'UP',
Expand Down Expand Up @@ -272,7 +271,7 @@ export type AnyUnknownUnionWithOthersType = any | unknown | string | number | bo
// Combinaion of any and unknown types with other types as an intersection
export type AnyUnknownIntersectionWithOthersType = any & unknown & string & number & boolean;


export type IntersectionTest = {a: string} & {a: number, b: number};
export interface AddressOptional {
street: any;
city: string;
Expand Down
1 change: 1 addition & 0 deletions input/literalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ export type AnyUnknownUnionWithOthersType = any | unknown | string | number | bo
// Combinaion of any and unknown types with other types as an intersection
export type AnyUnknownIntersectionWithOthersType = any & unknown & string & number & boolean;

export type IntersectionTest = {a: string} & {a: number, b: number};
Loading

0 comments on commit 55efb0d

Please sign in to comment.