Skip to content

Convert project from JavaScript to TypeScript - #174

Merged
jpaladin merged 16 commits into
stagefrom
copilot/convert-project-to-typescript
May 27, 2026
Merged

jpaladin merged 16 commits into
stagefrom
copilot/convert-project-to-typescript

Conversation

Copilot AI commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Convert all source files from JS to TS with strict mode, replacing the hand-maintained types/index.d.ts with auto-generated declarations.

Source conversion

  • src/{formUtils,useValidation,validationFunctions,index}.js → .ts
  • unknown over any for validation function parameters
  • Generic Field<T> interface so consumers get typed values
  • FieldConfig, Field, Fields exported as first-class types

Type generation

  • Added vite-plugin-dts with rollupTypes: true — produces a single rolled-up dist/index.d.ts
  • Removed types/index.d.ts and types from files in package.json

Build config

  • tsconfig.json: strict, ES2020, bundler module resolution
  • vite.config.js: entry updated to src/index.ts, dts plugin added, dual ESM/CJS output (index.mjs + index.cjs)
  • package.json: exports field with import/require conditions for ESM and CJS consumers; main → ./dist/index.cjs; module → ./dist/index.mjs; types → ./dist/index.d.ts

Test fixup

  • Removed .js extensions from explicit source imports in cypress tests
// Field<T> is now generic — consumers get typed values
const email: Field<string> = useValidation('', isValidEmail);

[!WARNING]

AleksandarDev and others added 3 commits February 3, 2026 13:11
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 7.3.1 to 7.3.2.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/v7.3.2/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v7.3.2/packages/vite)

---
updated-dependencies:
- dependency-name: vite
  dependency-version: 7.3.2
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Copilot AI linked an issue Apr 7, 2026 that may be closed by this pull request
Copilot AI and others added 4 commits April 7, 2026 11:47
Agent-Logs-Url: https://github.com/Enterwell/react-form-validation/sessions/d32bd755-2b97-431a-bda4-4cade686a26a

Co-authored-by: AleksandarDev <643171+AleksandarDev@users.noreply.github.com>
- Convert src/validationFunctions.js → src/validationFunctions.ts
- Convert src/formUtils.js → src/formUtils.ts
- Convert src/useValidation.js → src/useValidation.ts
- Convert src/index.js → src/index.ts with type re-exports
- Remove manual types/index.d.ts (now auto-generated via vite-plugin-dts)
- Add tsconfig.json with strict mode
- Update vite.config.js to use .ts entry and dts plugin
- Update package.json types field to point to dist/index.d.ts
- Add typescript and vite-plugin-dts as dev dependencies
- Update cypress test imports to remove .js extensions

Agent-Logs-Url: https://github.com/Enterwell/react-form-validation/sessions/024b1f72-0daf-4fca-813d-93f6e09775eb

Co-authored-by: AleksandarDev <643171+AleksandarDev@users.noreply.github.com>
Copilot AI changed the title [WIP] Convert the project from JS to TypeScript for better maintainability Convert project from JavaScript to TypeScript Apr 7, 2026
Copilot AI requested a review from AleksandarDev April 7, 2026 11:55
@AleksandarDev

Copy link
Copy Markdown
Contributor

@copilot remove any types that TS can resolve types from return/response

Copilot AI commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

@copilot remove any types that TS can resolve types from return/response

Removed all redundant return type annotations across all three source files in 1a887d9. TS now infers return types from the implementations — this also gives us richer inferred types in the generated .d.ts (e.g., isTrue becomes a v is true type guard, isNotNull becomes v is {} | undefined).

@jpaladin

jpaladin commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

@copilot
can we make changes to extractValues helper so it infers value types from fields using a few helpers like this

export type ExtractedValues<TFields extends Record<string, Field>> = {
[K in keyof TFields]: TFields[K] extends Field
? TValue
: never;
};

and implementaiton like this

export const extractValues = <
TFields extends Record<string, Field>

(
fields: TFields
): ExtractedValues => {
return Object
.entries(fields)
.reduce(
(acc, [key, field]) => ({
...acc,
[key]: field.value,
}),
{} as ExtractedValues
);
};

take into account these suggestions and if appropriate apply changes in this PR so we get more TS features on next release

@AleksandarDev

Copy link
Copy Markdown
Contributor

@copilot can we make changes to extractValues helper so it infers value types from fields using a few helpers like this

export type ExtractedValues<TFields extends Record<string, Field>> = {
[K in keyof TFields]: TFields[K] extends Field
? TValue
: never;
};

and implementaiton like this

export const extractValues = <
TFields extends Record<string, Field>

(
fields: TFields
): ExtractedValues => {
return Object
.entries(fields)
.reduce(
(acc, [key, field]) => ({
...acc,
[key]: field.value,
}),
{} as ExtractedValues
);
};

take into account these suggestions and if appropriate apply changes in this PR so we get more TS features on next release

Also fix merge conflicts and update branch from latest main.

@AleksandarDev
AleksandarDev marked this pull request as ready for review May 26, 2026 13:19
@github-actions

Copy link
Copy Markdown

@Copilot Version should be bumped!

@jpaladin

Copy link
Copy Markdown
Contributor

@copilot Fix the package build so this library can be consumed correctly by both ESM and CommonJS projects.

@jpaladin

Copy link
Copy Markdown
Contributor

@copilot Fix the package build so this library can be consumed correctly by both ESM and CommonJS projects.

auto-merge was automatically disabled May 27, 2026 08:31

Head branch was pushed to by a user without write access

Copilot AI commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Fix the package build so this library can be consumed correctly by both ESM and CommonJS projects.

Done in the latest commit. Changes made:

  • vite.config.js: Changed formats from ['cjs'] to ['es', 'cjs'] and set fileName to produce index.mjs (ESM) and index.cjs (CJS).
  • package.json: Added exports with import/require conditions, added module field pointing to index.mjs, and updated main to point to index.cjs.

The shared dist/index.d.ts (generated by vite-plugin-dts with rollupTypes: true) covers types for both entry points.

@github-actions

Copy link
Copy Markdown

@Copilot Version should be bumped!

@jpaladin
jpaladin enabled auto-merge May 27, 2026 09:18
@jpaladin
jpaladin marked this pull request as draft May 27, 2026 09:21
auto-merge was automatically disabled May 27, 2026 09:21

Pull request was converted to draft

@jpaladin
jpaladin marked this pull request as ready for review May 27, 2026 09:22
@jpaladin
jpaladin changed the base branch from master to stage May 27, 2026 09:25
@jpaladin

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

…ect-to-typescript

# Conflicts:
#	pnpm-lock.yaml

Copilot AI commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Done. Merged origin/stage into this branch — the only conflict was pnpm-lock.yaml (vite version and transitive dep differences). Resolved by regenerating it with pnpm install --no-frozen-lockfile after the auto-merged package.json picked up stage's bumped @types/react@19.2.14 and cypress@15.13.0. Build confirmed clean.

Copilot AI requested a review from jpaladin May 27, 2026 09:30
@jpaladin
jpaladin merged commit 1cd9d2f into stage May 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TS] Convert the project to typescript

3 participants