diff --git a/src/types/InvertPattern.ts b/src/types/InvertPattern.ts
index ecc7498b..966fdba7 100644
--- a/src/types/InvertPattern.ts
+++ b/src/types/InvertPattern.ts
@@ -318,7 +318,10 @@ type InvertPatternForExcludeInternal
=
? {
select: InvertPatternForExcludeInternal;
array: i extends readonly (infer ii)[]
- ? InvertPatternForExcludeInternal[]
+ ? MaybeAddReadonly<
+ InvertPatternForExcludeInternal[],
+ IsReadonlyArray
+ >
: empty;
map: subpattern extends [infer pk, infer pv]
? i extends Map
diff --git a/tests/exhaustive-match.test.ts b/tests/exhaustive-match.test.ts
index 34911f79..554447fd 100644
--- a/tests/exhaustive-match.test.ts
+++ b/tests/exhaustive-match.test.ts
@@ -979,4 +979,15 @@ describe('exhaustive()', () => {
expect(withoutTypo({ sex: 'b', age: 'c' })).toBe(1);
});
});
+
+ it('issue #271: P.array should exhaustively match readonly arrays', () => {
+ type Input = string | Date | readonly string[];
+ const input = ['a', 'b', 'c'] as Input;
+
+ const output = match(input)
+ .with(P.array(P.string), (value) => 1)
+ .with(P.string, (value) => 2)
+ .with(P.instanceOf(Date), (value) => 3)
+ .exhaustive();
+ });
});