|
| 1 | +import { tryCatch } from "@maxmorozoff/try-catch-tuple"; |
| 2 | + |
| 3 | +{ |
| 4 | + const [user, error] = tryCatch(parseUserJson('{"id":1}')); // ok |
| 5 | +} |
| 6 | +{ |
| 7 | + const [user, ,] = tryCatch(parseUserJson('{"id":1}')); // ok |
| 8 | +} |
| 9 | +{ |
| 10 | + const [user] = tryCatch(parseUserJson('{"id":1}')); |
| 11 | +} |
| 12 | +{ |
| 13 | + const wrappedTryCatch = () => tryCatch(parseUserJson('{"id":1}')); |
| 14 | + const [user] = wrappedTryCatch(); |
| 15 | +} |
| 16 | +{ |
| 17 | + const wrappedTryCatch = () => tryCatch(fetchMeUser); |
| 18 | + const user = await wrappedTryCatch(); |
| 19 | +} |
| 20 | + |
| 21 | +{ |
| 22 | + const [result] = await tryCatch(fetchMeUser); |
| 23 | +} |
| 24 | +{ |
| 25 | + const result = tryCatch(() => null); |
| 26 | +} |
| 27 | +function foo() { |
| 28 | + const result = tryCatch(() => null); |
| 29 | +} |
| 30 | +const bar = () => { |
| 31 | + const result = tryCatch(() => null); |
| 32 | +}; |
| 33 | +// const data = tryCatch(() => null); |
| 34 | +// let data1 = tryCatch(() => null); |
| 35 | +// export const result = tryCatch(() => null); |
| 36 | + |
| 37 | +{ |
| 38 | + { |
| 39 | + const [result] = tryCatch(() => null); |
| 40 | + } |
| 41 | + { |
| 42 | + // biome-ignore lint/complexity/noUselessLoneBlockStatements: |
| 43 | + // biome-ignore lint/style/noVar: |
| 44 | + // biome-ignore lint/correctness/noInnerDeclarations: |
| 45 | + var [result] = tryCatch(() => null); |
| 46 | + } |
| 47 | + { |
| 48 | + // biome-ignore lint/style/useSingleVarDeclarator: |
| 49 | + const foo = "bar", |
| 50 | + [result] = tryCatch(() => null); |
| 51 | + } |
| 52 | + { |
| 53 | + const wrappedTryCatch = () => tryCatch(() => null); |
| 54 | + const [result] = wrappedTryCatch(); |
| 55 | + } |
| 56 | + { |
| 57 | + const wrappedTryCatch = () => tryCatch(async () => null); |
| 58 | + const [result] = await wrappedTryCatch(); |
| 59 | + } |
| 60 | + { |
| 61 | + const [result] = await tryCatch(async () => null); |
| 62 | + } |
| 63 | + { |
| 64 | + const result = tryCatch(() => null); |
| 65 | + } |
| 66 | + function foo() { |
| 67 | + const result = tryCatch(() => null); |
| 68 | + } |
| 69 | + const bar = () => { |
| 70 | + const result = tryCatch(() => null); |
| 71 | + }; |
| 72 | + const data = tryCatch(() => null); |
| 73 | + // biome-ignore lint/style/useConst: <explanation> |
| 74 | + let data1 = tryCatch(() => null); |
| 75 | + const result = tryCatch(() => null); |
| 76 | +} |
| 77 | + |
| 78 | +type User = { id: number }; |
| 79 | +async function fetchMeUser() { |
| 80 | + return {} as User; |
| 81 | +} |
| 82 | +function parseUserJson(jsonString: string) { |
| 83 | + return () => JSON.parse(jsonString) as User; |
| 84 | +} |
0 commit comments