Negated types · Issue #4196 · microsoft/TypeScript (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd

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.

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

Another example

export NonIdentifierExpression = ts.Expression ~ ts.Identifier