mammoth icon indicating copy to clipboard operation
mammoth copied to clipboard

`Array<Token>` is assignable to `Token`

Open cakoose opened this issue 3 years ago • 0 comments

I sometimes have to use Token to build expressions that Mammoth doesn't currently support. I noticed that Array<Token> is assignable to Token:

import {Token} from '@ff00ff/mammoth/.build/tokens';

const ts = 
function f(ts: Array<Token>): Token {
    return ts; // was expecting a type error here
}

This means TS doesn't catch errors where I accidentally pass Array<Token> where a Token is expected.

Maybe Mammoth should change Token to be nominally typed to avoid this issue?

cakoose avatar Jan 20 '22 19:01 cakoose