Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't think this is right, for two reasons:

1. As a nit-pick "unconstrained object" is not best modeled by `unknown` because that includes non-objects as well, there's better types to use for that

2. Someone asking you for any unconstrained data would also be `unknown`

`any` is not a type at all, it is an annotation to disable the type system



I suspect they were talking more about general terminology than TypeScript's specific usage of `unknown` and `any`.

"This box contains an unknown item" and "I'll accept any item" both sound natural, while "this box contains any item" and "I'll accept an unknown item" both sound weird (to me, anyway).


Hmm, I'm not sure about that interpretation, they said "It’s technically the same type from two perspectives."

It's not the same type at all. I do agree with your example of the usage of those words in spoken English, but I don't think that is what we're going for in a discussion in Sets, Types, and Type Checking


If we step away from any particular language:

If I give you a reference, address, or some other identifier, for something you know nothing else about, you can't do anything with the reference but pass it on. You have no information about the thing itself. You don't even know how to dereference the reference.

Whatever it is that I gave you a reference for, is unknown to you.

Now if I say, go ahead and give me some thing, with no constraints, you can give me any thing.

Which without further information, will just be a reference to an unknown to me.

Mathematically, "unknown" and "any" both represent something without any constraints or information known about them, but in opposite roles.

But one is when you receive a reference to something you know nothing else about, the other is when you provide something without any requirement to give any information about it.

The two roles necessarily happen simultaneously in that exchange.

--

I expect in most languages that "unknown" and "any" gets used, this gets watered down.

Most languages provide some kind of baseline information with the "things" in it. For instance, objects whose type can be always be queried via reflection, or some other baseline accessible information.

Also, languages use words differently. So maybe they are not consistent with the unknown/any symmetry I described at all.




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

Search: