total-typescript / ts-reset

A 'CSS reset' for TypeScript, improving types for common JavaScript API's

Home Page:https://www.totaltypescript.com/ts-reset

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request - Do not allow arrays to be assigned to a Record

kush-daga opened this issue · comments

let el: Record<string, any> = {foo: 'bar'}
let arr = [1,2,3]

el = arr; // this won't give an error

Currently we are allowed to write this code in TypeScript.

This might be intended as internally the types might match (and also that the record has any), but this causes subtle confusion in codebases, as the one I am working on right now, where a function accepts an object but we are passing it an array, which is giving runtime errors then.

I might be thinking wrong here and probably not sure if this should be a part of ts-reset, but would love to understand more.

We won't be able to do anything about this - and I'm not sure we'd want to anyway! When it comes down to it, arrays are objects.