diff --git a/packages/type-utils/tests/isTypeReadonly.test.ts b/packages/type-utils/tests/isTypeReadonly.test.ts index 7153b44d7769..4054b0db1f0b 100644 --- a/packages/type-utils/tests/isTypeReadonly.test.ts +++ b/packages/type-utils/tests/isTypeReadonly.test.ts @@ -215,5 +215,56 @@ describe('isTypeReadonly', () => { }); }); }); + + describe('Conditional Types', () => { + describe('is readonly', () => { + it('handles a conditional type that is readonly', () => { + const { type, checker } = getType( + `type Test = T extends readonly number[] ? readonly string[] : readonly number[];`, + ); + + const result = isTypeReadonly(checker, type); + expect(result).toBe(true); + }); + + it('should ignore a mutable condition', () => { + const { type, checker } = getType( + `type Test = T extends number[] ? readonly string[] : readonly number[];`, + ); + + const result = isTypeReadonly(checker, type); + expect(result).toBe(true); + }); + }); + + describe('is not readonly', () => { + it('fails with a conditional type that is mutables', () => { + const { type, checker } = getType( + `type Test = T extends number[] ? string[] : number[];`, + ); + + const result = isTypeReadonly(checker, type); + expect(result).toBe(false); + }); + + it('fails with a conditional type that is mutable or readonly', () => { + const { type, checker } = getType( + `type Test = T extends number[] ? string[] : readonly number[];`, + ); + + const result = isTypeReadonly(checker, type); + expect(result).toBe(false); + }); + + it('fails with a conditional type that is readonly or mutable', () => { + const { type, checker } = getType( + `type Test = T extends number[] ? readonly string[] : number[];`, + ); + + const result = isTypeReadonly(checker, type); + expect(result).toBe(false); + }); + }); + }); }); });