As it is mentioned in this thread:
https://github.com/timdown/rangy/issues/136
The issue is fixed in new version.
yet if you still have issue try using it this way:
let expandWord = rangy.getSelection();
expandWord.expand("word", {
trim: true
});
Plus:
To avoid error message in angular2+. add its types as below.
try installing the types for Rangy:
npm install --save @types/rangy
Afterwards edit the index.d.ts file and add expand function to the types. in RangySelection Interface.
interface RangySelection extends Selection {
nativeSelection: Selection;
isBackwards(): boolean;
refresh(checkForChanges?: boolean): any;
toHtml(): string;
getAllRanges(): RangyRange[];
getRangeAt(idx: number): RangyRange;
getNativeTextRange(): any;
setSingleRange(range: RangyRange): any;
setRanges(ranges: RangyRange[]): any;
getBookmark(containerNode: Node): any;
moveToBookmark(bookmark: Object): any;
saveRanges(): Object;
restoreRanges(saved: Object): any;
saveCharacterRanges(containerNode: Node, opts?: any): Object;
restoreCharacterRanges(containerNode: Node, characterRanges: Object, opts?: any): any;
detach(): any;
inspect(): string;
move(units: string, count: number, opts?: any): number;
//This One
expand(session, unit?, expandOptions?);
}