Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[documentation] Clarify the semantics of void #20006

Copy link
Copy link
@pelotom

Description

@pelotom
Issue body actions

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!

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

SpecIssues related to the TypeScript language specificationIssues related to the TypeScript language specification

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.