diff --git a/src/tests/array-includes.ts b/src/tests/array-includes.ts index 2b23a96..6d05a06 100644 --- a/src/tests/array-includes.ts +++ b/src/tests/array-includes.ts @@ -59,6 +59,47 @@ doNotExecute(async () => { } }); +doNotExecute(async () => { + /** + * type narrowing for numbers in readonly array + */ + let arr = [1, 2, 3] as const; + + let member = 1 as 1 | 2 | 4; + if (arr.includes(member)) { + type tests = [Expect>]; + } +}); + +doNotExecute(async () => { + /** + * type narrowing for objects in readonly array + */ + const arr = [{ a: 1 }, { a: 2 }, { a: 3 }] as const; + + arr.includes( + // @ts-expect-error + 4, + ); + + let member = { a: 1 } as const; + if (arr.includes(member)) { + type tests = [Expect>]; + } +}); + +doNotExecute(async () => { + /** + * type narrowing for objects in writable array + */ + let arr: Array<1 | 2 | 3> = [1, 2, 3]; + + let member = 1 as 1 | 2 | 4; + if (arr.includes(member)) { + type tests = [Expect>]; + } +}); + doNotExecute(async () => { const arr: Array<"1" | "2" | "3"> = ["1", "2", "3"]; @@ -73,3 +114,12 @@ doNotExecute(async () => { true, ); }); + +doNotExecute(async () => { + const arr: Array<1 | 2 | 3> = [1, 2, 3]; + + let member = 4 as 3 | 4; + if (arr.includes(member)) { + type tests = [Expect>]; + } +});