Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Convert to TypeScript and ensure strict type safety #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
XDGFX wants to merge 11 commits into mattphillips:main
base: main
Choose a base branch
Loading
from XDGFX:ts-strict

Conversation

@XDGFX
Copy link

@XDGFX XDGFX commented Mar 3, 2024

Overview

Inspired by PR #98 and #99, and with the desire to use Typia functions which means types must be properly defined, I have ported all the JS functions to fully typed TS.

The only function signature change is in src/utils.ts, where the hasOwnProperty method expects a PropertyKey parameter, so I updated the function to expect that type only.
No other function signatures are changed.

The benefit is that for all functions, TS users have a reliable type output based on the types supplied as inputs. No change to JS users.

Ensured that build, lint, test, and test:coverage all pass without errors. Replaced yarn commands with npm as yarn was not specified as a devDependency.

Types

The main types returned by the various diff functions are now defined as follows:

export type DiffDeletedType<T, U> =
 | {
 [P in Exclude<keyof ElementType<T>, keyof ElementType<U>>]: undefined;
 }
 | EmptyObject;
export type DiffAddedType<T, U> =
 | {
 [P in Exclude<
 keyof ElementType<U>,
 keyof ElementType<T>
 >]: ElementType<U>[P];
 }
 | EmptyObject;
export type DiffUpdatedType<T, U> =
 | {
 [P in keyof ElementType<T> & keyof ElementType<U>]?: DiffUpdatedType<
 ElementType<T>[P],
 ElementType<U>[P]
 >;
 }
 | U
 | EmptyObject;
export type DiffType<T, U> =
 | U
 | (DiffAddedType<T, U> & DiffDeletedType<T, U> & DiffUpdatedType<T, U>);

The types were determined by reading the function code and ensuring the returned values match the specified type.

Bessonov and jahirfiquitiva reacted with heart emoji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /