microsoft / microsoft/TypeScript

Negated types

Open
#4,196 67 comments 177 reactions 0 assignees View on GitHub
In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Sometimes it is desired to forbid certain types from being considered.

Example: `JSON.stringify(function() {});` doesn't make sense and the chance is high it's written like this by mistake. With negated types we could eliminate a chance of it.

``` typescript
type Serializable = any ~ Function; // or simply ~ Function
declare interface JSON {
stringify(value: Serializable): string;
}
```

Another example

``` typescript

export NonIdentifierExpression = ts.Expression ~ ts.Identifier

```

Contributor guide

Open the contributing guide

Research direction

No files, tests, or entry points are named. Start by reviewing the proposed Serializable and NonIdentifierExpression examples, then determine the required type-system behavior and its effects on assignability; done means negated types are supported consistently and covered by appropriate tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.