forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnarrowingUnionByUnionCandidate1.js
More file actions
44 lines (36 loc) · 1.1 KB
/
narrowingUnionByUnionCandidate1.js
File metadata and controls
44 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//// [tests/cases/compiler/narrowingUnionByUnionCandidate1.ts] ////
//// [narrowingUnionByUnionCandidate1.ts]
// https://github.com/microsoft/TypeScript/issues/61581
type Result<A, E> =
| {
readonly _tag: "Ok";
readonly value: A;
}
| {
readonly _tag: "Fail";
readonly error: E;
};
declare const isResult: (u: unknown) => u is Result<any, any>;
// return type: Result<A, E> | "ok"
export const fn = <A, E>(inp: Result<A, E> | string) =>
isResult(inp) ? inp : "ok";
//// [narrowingUnionByUnionCandidate1.js]
"use strict";
// https://github.com/microsoft/TypeScript/issues/61581
Object.defineProperty(exports, "__esModule", { value: true });
exports.fn = void 0;
// return type: Result<A, E> | "ok"
var fn = function (inp) {
return isResult(inp) ? inp : "ok";
};
exports.fn = fn;
//// [narrowingUnionByUnionCandidate1.d.ts]
type Result<A, E> = {
readonly _tag: "Ok";
readonly value: A;
} | {
readonly _tag: "Fail";
readonly error: E;
};
export declare const fn: <A, E>(inp: Result<A, E> | string) => Result<A, E> | "ok";
export {};