#Implicit methods on object types

12 messages · Page 1 of 1 (latest)

night crypt
timber cragBOT
#

@night crypt Here's a shortened URL of your playground link! You can remove the full link from your message.

furan2424#0

Preview:```ts
declare const f: <A extends { toString: () => string; }>(arg: A) => void;

type X = {};
interface Y { };
type Z = null | undefined;
type W = never;
type T = unknown;
type V = void;
type N = any;

f(2 as X);
f(3 as Y);
f(4 as Z);
f(5 as W); //Is this is a bug?
...```

silk garden
#

By definition, never is a subset of all types

#

But it's not a problem as that is no value of the never type, so "never" can never actually be passed

#

If your logic indicates that a value of type never is going to be passed, what this really means (assuming the type logic is correct) is that that code is unreachable.

brittle mist
#

never is the bottom type, it is a subtype to all types (including itself)

#

oh goddamnit did not scroll

#

(see also the methods right below)

#

you can create an object without those props by using a null prototype, ie Object.create(null) but afaik ts can't represent that