Open
Conversation
…hin a store containing a string or an array
earthspacon
reviewed
Nov 16, 2024
src/includes/index.ts
Outdated
Comment on lines
+20
to
+24
| if (typeof a === 'number') { | ||
| throw new Error('first argument should be an unit of array or string'); | ||
| } | ||
|
|
||
| return a.includes(b as string); |
Contributor
There was a problem hiding this comment.
a must be either an array or a string, so I would write it like this:
if (typeof a === 'string') {
return a.includes(b as string);
}
throw new Error('First argument should be a unit of array or string');I'm not a maintainer, just decided to leave a comment :)
sergeysova
requested changes
Mar 18, 2025
Comment on lines
+7
to
+10
| export function includes <T extends string | number>( | ||
| a: Store<Array<T>>, | ||
| b: Store<T> | T, | ||
| ): Store<boolean> |
Comment on lines
+3
to
+10
| export function includes <T extends string>( | ||
| a: Store<T>, | ||
| b: Store<T> | T, | ||
| ): Store<boolean> | ||
| export function includes <T extends string | number>( | ||
| a: Store<Array<T>>, | ||
| b: Store<T> | T, | ||
| ): Store<boolean> |
Member
There was a problem hiding this comment.
What if:
Suggested change
| export function includes <T extends string>( | |
| a: Store<T>, | |
| b: Store<T> | T, | |
| ): Store<boolean> | |
| export function includes <T extends string | number>( | |
| a: Store<Array<T>>, | |
| b: Store<T> | T, | |
| ): Store<boolean> | |
| export function includes <T extends string>( | |
| a: Store<T>, | |
| b: Store<T> | T, | |
| ): Store<boolean> | |
| export function includes <T>( | |
| a: Store<Array<T>>, | |
| b: Store<T> | T, | |
| ): Store<boolean> | |
| export function includes <T>( | |
| a: Store<{ ref: Set<T> }>, | |
| b: Store<T> | T, | |
| ): Store<boolean> |
allow to compare with any list of items?
Comment on lines
+12
to
+13
| a: Store<T | Array<T>>, | ||
| b: Store<T> | T, |
Member
There was a problem hiding this comment.
Suggested change
| a: Store<T | Array<T>>, | |
| b: Store<T> | T, | |
| haystack: Store<T | Array<T>>, | |
| needle: Store<T> | T, |
Member
There was a problem hiding this comment.
I think a, b is not clearly explains what in what we checking:
includes($email, "@");
includes("@", $email);it will work by types in both ways, but IDE will suggest a:, b: names which is not self-descriptive, I think
sergeysova
reviewed
Mar 18, 2025
| const $array = createStore([1, 2, 3]); | ||
| const $isInclude = includes($array, 2); | ||
|
|
||
| console.assert($isInclude.getState() === true); |
Member
There was a problem hiding this comment.
I think is better do not recommend using .getState() in documentation.
Suggested change
| console.assert($isInclude.getState() === true); | |
| $isInclude // => true |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
includesis implemented according to the issueThe operator checking if a store (containing either a string or an array) includes a specified value.
Checklist for a new method
srcdirectory inparam-casesrc/method-name/index.tsin ESModules export incamelCasenamed exportsrc/method-name/method-name.test.tssrc/method-name/method-name.fork.test.tstest-typings/method-name.ts// @ts-expect-errorto mark expected type errorimport { expectType } from 'tsd'to check expected return typesrc/method-name/readme.mdPatronum/MethodNameMotivation,Formulae,ArgumentsandReturnsections for each overloadExamplesection for each overloadsrc/method-name/readme.mdtitle. Make sure it uses camelCase syntax just like the method itselfslug. Use param-case to write it. In most cases it will be just liketitledesriptionwith one short sentence describing what method useful forgroup. To categorize method on/operatorspage. Full list of available groups, you can see in documentation/src/content/config.ts