lichess-org / chessground

Mobile/Web chess UI for lichess.org
https://lichess.org
GNU General Public License v3.0
1.05k stars 260 forks source link

Typescript magic #157

Closed topce closed 3 years ago

topce commented 3 years ago

update libs small improvements in typescript typing

export type Key = 'a0' |${File}${Rank};

export function callUserFunction<T extends (...args: any) => void>( f: T | undefined, ...args: Parameters<T> ): void { if (f) setTimeout(() => f(args), 1); }

fix compile time errors add premove: false, not sure if should be true ?

commit dist files

topce commented 3 years ago

@niklasf indeed it was error I commit fix to call apply if (f) setTimeout(() => f.apply(null,args), 1); if try to call it like before if (f) setTimeout(() => f(...args), 1); there is TS compile error (parameter) args: Parameters Type 'Parameters' must have a '[Symbol.iterator]()' method that returns an iterator.ts(2488)

still if you want to get rid of error and do not call apply it could be ignored // @ts-ignore if (f) setTimeout(() => f(...args), 1);

topce commented 3 years ago

create bug 41728 in TypeScript repo

topce commented 3 years ago

@niklasf with last commit it should work same way like before with f(...args) it look like when you call spread operator in function in typescript is not same as if you call apply in javascript it is same but not in TS trick was to change any -> any[] ugly but it works better than other solutions ;-)

niklasf commented 3 years ago

Looks good, thanks!