Skip to content

Commit

Permalink
fix : TypedString's startsWith method allow to use TypedClass parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
kakasoo committed Jan 3, 2024
1 parent 2f497f3 commit bfe6871
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/classes/typed-string.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ export class TypedString<T extends string | number | boolean = ''>
/**
* @inheritdoc
*/
startsWith<SearchString extends string, Position extends number>(
searchString: SearchString,
position?: Position,
startsWith<SearchString extends string = '', Position extends number = 0>(
searchString: SearchString | TypedString<SearchString> = new TypedString(),
position: Position | TypedNumber<Position> = new TypedNumber(),
): TypedBoolean<ReturnType<typeof StringPrototype.startsWith<`${T}`, SearchString, Position>>> {
const initialValue = StringPrototype.startsWith(this.string, searchString, position);
const primitiveSearchString = this.isTypedClass(searchString) ? searchString.toPrimitive() : searchString;
const primitivePosition = this.isTypedClass(position) ? position.toPrimitive() : position;
const initialValue = StringPrototype.startsWith(this.string, primitiveSearchString, primitivePosition);
return new TypedBoolean(initialValue);
}

Expand Down

0 comments on commit bfe6871

Please sign in to comment.