microsoft / microsoft/TypeScript

Negated types

Open
#4,196 67 comments 177 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

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.