Skip to content

[documentation] Clarify the semantics of void #20006

Closed

Description

In the handbook, it's stated that

void is a little like the opposite of any: the absence of having any type at all.

and

Declaring variables of type void is not useful because you can only assign undefined or null to them

The latter statement is not true in any useful sense; null is not assignable to void with --strictNullChecks enabled, i.e. it's no more assignable to void than any other type, so might as well not mention it.

The former is (maybe?) approximately true, but how about saying exactly what it means? I for one have never been 100% sure and would love to have some clarity. For instance, the unknown type,

type unknown = {} | undefined | null

is supposed to be a "top" type, i.e. any value should belong to it. And yet, void is not assignable to it.

declare const v: void
const foo: unknown = v
//    ^^^ Type 'void' is not assignable to type 'unknown'.

Why is that? According to the above, only undefined (and null, if no --strictNullChecks) inhabit void, so why is it not assignable to unknown?

Since there is no longer a current language specification, it seems the best available documentation is to be found at https://www.typescriptlang.org/docs/home.html, so it would be great if it could give a crisp definition of void!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

SpecIssues related to the TypeScript language specification

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions