Skip to content

chore: update typescript experience #10628

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

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/core/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
export function isString(value: any): boolean {
export function isString(value: any): value is string {
return typeof value === 'string' || value instanceof String;
}

export function isNumber(value: any): boolean {
export function isNumber(value: any): value is number {
return typeof value === 'number' || value instanceof Number;
}

export function isBoolean(value: any): boolean {
export function isBoolean(value: any): value is boolean {
return typeof value === 'boolean' || value instanceof Boolean;
}

export function isFunction(value: any): boolean {
export function isFunction(value: any): value is Function {
if (!value) {
return false;
}

return typeof value === 'function';
}

export function isObject(value: any): boolean {
export function isObject(value: any): value is Record<string,any> {
if (!value) {
return false;
}

return typeof value === 'object';
}

Comment on lines +21 to 27

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an invalid type guard.

an array, date, regex, class would also result in true but is not of type Record<string, any>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@farfromrefug you should take a look at this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@offizium-berndstorath indeed it would not work with Date/Regex ... However i dont think that s what that method was intended for seeing where it is used. In this case i think we should have a isDate, isRegex ...
I mean i dont see any place where isObject would be called with a Date, Regex, ...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@farfromrefug you are correct. these are not really what im concerned about. its mostly about array

export function isUndefined(value: any): boolean {
export function isUndefined(value: any): value is undefined {
return typeof value === 'undefined';
}

Expand Down
Loading