-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Search Terms
- unknown type
- unknown type union
- make unknown type union
Suggestion
unknown
would be a union of all lower‑case built‑in types, i.e.:
type unknown = string | number | bigint | boolean | symbol | object | null | undefined;
Use Cases
When describing an API that takes all‑but‑one primitive type, it’s useful to be able to do Exclude<unknown, symbol>
or Exclude<unknown, number | bigint>
without needing #29317.
Examples
- From DefinitelyTyped/DefinitelyTyped#44805:
-
/** * @see https://tc39.es/ecma262/#sec-createhtml */ export function CreateHTML( string: Exclude<unknown, string>, // unknown & not string, tag: string, attribute: string, value?: Exclude<unknown, string>, // unknown & not string, ): string; /** * @throws {TypeError} If `x` or `y` is a `number` or `bigint` or they're different types. * @see https://tc39.es/ecma262/#sec-samevaluenonnumeric */ export function SameValueNonNumeric( x: Exclude<unknown, number | bigint>, // unknown & not (number | bigint), y: Exclude<unknown, number | bigint>, // unknown & not (number | bigint), ): boolean;
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- There’s the possibility that some code somewhere depends on
Exclude<unknown, something>
returningunknown
.
- There’s the possibility that some code somewhere depends on
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Related
nicu-chiciuc
Metadata
Metadata
Assignees
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript