Trailing comma in type alias causes TS1003 identifier expected compiler error
This causes a TS1003 error on the comma after the third parameter:
export type PriceLookup = (
tokenAddress: string,
block: i32,
currentPool: string,
) => string | null;
ERROR TS1003: Identifier expected.
;; :
;; 4 │ currentPool: string,
;; │ ^
;; └─ in module.ts(4,22)
;;
;; ERROR TS1012: Unexpected token.
;; :
;; 4 │ currentPool: string,
;; │ ^
;; └─ in module.ts(4,22)
This compiles fine:
export type PriceLookup2 = (tokenAddress: string, block: i32, currentPool: string) => string | null;
Functionally, there is no difference between these. However, eslint/prettier will often cause example 2 to be wrapped into the format of example 1, so it would be nice for this to not error.
Basically problem with trilling comma. This will work:
export type PriceLookup = (
tokenAddress: string,
block: i32,
currentPool: string // removed last comma
) => string | null;
Yep, I realise that. It's a common rule in prettier/eslint to add the trailing comma (hence linting doesn't pick up on this). Does the AS compiler (transpiler?) in general report problems with trailing commas? If so, I'll amend our linting rules. It would be nice for that to be mentioned somewhere, though!
AS supports trailing commas even in cases where TS fails. We just accidentally miss this case.
Yes, I just confirmed that trailing commas are generally supported. e.g this works:
pushArray(
records,
getERC20TokenRecordsFromWallets(timestamp, contractAddress, contract, rate, blockNumber),
);