Hacker News new | past | comments | ask | show | jobs | submit login
I Hate "Unknown"
2 points by h_tbob 16 days ago | hide | past | favorite | 4 comments
Does anybody else think unknown is a useless, worthless, hateful bug in Typescript? There has never been a single time when it helped me and it annoys me 100% of the time. Why isn't there a way to turn it off?

I'm so mad right now because there's no tsconfig option to turn it off. Why not. Does anybody smarter than me have a good explanation for why they put it in so I can quit getting mad when it says this:

``` const d = reactive({ searchText: "", customers: null as any[], <-- Conversion of type 'null' to type 'any[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.ts(2352)

    page: 1,
    perPage: 10,
    gettingCustomers: false,
    error: ""
}); ```



Why not use an empty array instead of null for the default value?


Why null as any[]? Can’t it just be []?


Actually, if you do that you get:

"Property 'email' does not exist on type 'never'.ts(2339)"

When you do

{{customer.email}}


Use `[] as TheRealType`. `any` is the real wart on the language, not unknown, which adds safety by preventing you from doing anything dangerous with it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: