Comparing version
declare const corrupt: (unreachable: never) => never; | ||
type AnyFunction = (...args: any[]) => unknown; | ||
type ExhaustiveUnion<Union extends string> = { | ||
type ExhaustiveUnion<Union extends string | boolean> = Union extends string ? { | ||
[Key in Union]: (value: Key) => any; | ||
} & ExhaustiveFallback; | ||
type ExhaustiveTag<Union extends object, Tag extends keyof Union> = { | ||
[Key in Union[Tag] & string]: (value: Extract<Union, { | ||
} & ExhaustiveFallback : Union extends boolean ? { | ||
[Key in `${Union}`]: (value: Key extends 'true' ? true : false) => any; | ||
} & ExhaustiveFallback : never; | ||
type ExhaustiveTag<Union extends object, Tag extends keyof Union, Values extends Union[Tag] = Union[Tag]> = Values extends string ? { | ||
[Key in Values]: (value: Extract<Union, { | ||
[K in Tag]: Key; | ||
}>) => any; | ||
} & ExhaustiveFallback; | ||
} & ExhaustiveFallback : Values extends boolean ? { | ||
[Key in `${Values}`]: (value: Extract<Union, { | ||
[K in Tag]: Key extends 'true' ? true : false; | ||
}>) => any; | ||
} & ExhaustiveFallback : never; | ||
type ExhaustiveFallback = { | ||
@@ -28,8 +34,8 @@ /** | ||
}; | ||
declare function exhaustive<Union extends string, Match extends ExhaustiveUnion<Union> = ExhaustiveUnion<Union>, Output = Match[keyof Match] extends AnyFunction ? ReturnType<Match[keyof Match]> : never>(union: Union, match: ValidateKeys<Match, ExhaustiveUnion<Union>>): Output; | ||
declare function exhaustive<Union extends string | boolean, Match extends ExhaustiveUnion<Union> = ExhaustiveUnion<Union>, Output = Match[keyof Match] extends AnyFunction ? ReturnType<Match[keyof Match]> : never>(union: Union, match: ValidateKeys<Match, ExhaustiveUnion<Union>>): Output; | ||
declare function exhaustive<Union extends object, Tag extends keyof Union, Match extends ExhaustiveTag<Union, Tag> = ExhaustiveTag<Union, Tag>, Output = Match[keyof Match] extends AnyFunction ? ReturnType<Match[keyof Match]> : never>(union: Union, tag: Tag, match: ValidateKeys<Match, ExhaustiveTag<Union, Tag>>): Output; | ||
declare namespace exhaustive { | ||
var tag: <Union extends object, Tag extends keyof Union, Match extends ExhaustiveTag<Union, Tag> = ExhaustiveTag<Union, Tag>, Output = Match[keyof Match] extends AnyFunction ? ReturnType<Match[keyof Match]> : never>(union: Union, tag: Tag, match: ValidateKeys<Match, ExhaustiveTag<Union, Tag>>) => Output; | ||
var tag: <Union extends object, Tag extends keyof Union, Match extends ExhaustiveTag<Union, Tag, Union[Tag]> = ExhaustiveTag<Union, Tag, Union[Tag]>, Output = Match[keyof Match] extends AnyFunction ? ReturnType<Match[keyof Match]> : never>(union: Union, tag: Tag, match: ValidateKeys<Match, ExhaustiveTag<Union, Tag, Union[Tag]>>) => Output; | ||
} | ||
export { ExhaustiveTag, ExhaustiveUnion, corrupt, exhaustive }; |
@@ -1,1 +0,1 @@ | ||
"use strict";var r=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var x=(t,n)=>{for(var e in n)r(t,e,{get:n[e],enumerable:!0})},g=(t,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of f(n))!h.call(t,i)&&i!==e&&r(t,i,{get:()=>n[i],enumerable:!(o=p(n,i))||o.enumerable});return t};var T=t=>g(r({},"__esModule",{value:!0}),t);var U={};x(U,{corrupt:()=>a,exhaustive:()=>s});module.exports=T(U);var a=t=>{let n=e=>{if(typeof e=="symbol")return e.toString();if(typeof e=="undefined")return"undefined";if(typeof e=="string")return e;try{return JSON.stringify(e)}catch(o){if(o instanceof TypeError)return typeof e=="bigint"?`${e.toString()} (bigint)`:"circular object";throw o}};throw new TypeError(`Internal Error: encountered impossible value "${n(t)}"`)};function s(t,n,e){if(typeof e!="undefined"){let c=t,y=n;return s.tag(c,y,e)}let o=t,i=n;if(!Object.prototype.hasOwnProperty.call(i,o))return Object.prototype.hasOwnProperty.call(i,"_")?i._():a(o);let u=i[o];return u(o)}s.tag=(t,n,e)=>{let o=t[n];if(!Object.prototype.hasOwnProperty.call(e,o))return Object.prototype.hasOwnProperty.call(e,"_")?e._():a(t);let i=e[o];return i(t)};0&&(module.exports={corrupt,exhaustive}); | ||
"use strict";var r=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var p=(n,t)=>{for(var e in t)r(n,e,{get:t[e],enumerable:!0})},g=(n,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of f(t))!h.call(n,o)&&o!==e&&r(n,o,{get:()=>t[o],enumerable:!(a=x(t,o))||a.enumerable});return n};var l=n=>g(r({},"__esModule",{value:!0}),n);var d={};p(d,{corrupt:()=>i,exhaustive:()=>s});module.exports=l(d);var i=n=>{let t=e=>{if(typeof e=="symbol")return e.toString();if(typeof e=="undefined")return"undefined";if(typeof e=="string")return e;try{return JSON.stringify(e)}catch(a){if(a instanceof TypeError)return typeof e=="bigint"?`${e.toString()} (bigint)`:"circular object";throw a}};throw new TypeError(`Internal Error: encountered impossible value "${t(n)}"`)};function s(n,t,e){if(typeof e!="undefined"){let y=n,c=t;return s.tag(y,c,e)}let a=n,o=t;if(!Object.prototype.hasOwnProperty.call(o,a))return Object.prototype.hasOwnProperty.call(o,"_")?o._():i(a);let u=o[a];return u(a)}s.tag=(n,t,e)=>{let a=n[t];if(!Object.prototype.hasOwnProperty.call(e,a))return Object.prototype.hasOwnProperty.call(e,"_")?e._():i(n);let o=e[a];return o(n)};0&&(module.exports={corrupt,exhaustive}); |
{ | ||
"name": "exhaustive", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Exhaustiveness checking in TypeScript", | ||
@@ -5,0 +5,0 @@ "author": "Luke Morales <lukemorales@live.com>", |
Sorry, the diff of this file is not supported yet
13846
3.34%49
16.67%