From 610f0df37adc5542d448dd6d5f47e15bf4a4beb4 Mon Sep 17 00:00:00 2001 From: AshGw Date: Fri, 26 Apr 2024 04:49:48 +0100 Subject: [PATCH] docs: enhance docs for `@Frozen` --- README.md | 4 ++-- src/index.ts | 38 ++++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ecd8213b..8bffcdbd 100644 --- a/README.md +++ b/README.md @@ -116,9 +116,9 @@ test using a testing framework. Here's an example with [`vitest`](https://vitest import type { Abs, TestType } from 'ts-roids'; import { test, expect , expectTypeOf} from 'vitest'; -test('|-54| should be 54'() => { +test('|-54| should be 54',() => { type ShouldPass = true; - expectTypeOf, 54, ShouldPass>>().toEqualTypeOf(); + expectTypeOf, 54, true>>().toEqualTypeOf(); }); ```` diff --git a/src/index.ts b/src/index.ts index bc3dc4b1..8e3c46d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1666,24 +1666,26 @@ const _freeze = (obj: object) => { * * @example * ```ts - * @Frozen - * class Foo { - * foo: T; - * bar: string; - * - * constructor(foo: T) { - * this.foo = foo; - * this.bar = 'bar'; - * } - * - * someFoo(): T { - * return this.foo; - * } - * } - * - * const foo = new Foo('foo'); - * // The line below will cause a TypeError: Cannot assign to read only property 'bar' - * foo.bar = 'altered bar'; +@Frozen +class Foo { + foo: T; + bar?: MaybeUndefined; + + constructor(foo: T) { + this.foo = foo; + this.bar = 'bar'; + } + + someFoo(): T { + return this.foo; + } +} + +const foo = new Foo('foo'); +// The line below will cause a TypeError: Cannot assign to read only property 'bar' +foo.bar = 'altered bar'; +// The line below will cause a TypeError: Cannot delete property 'bar' +delete foo.bar; * ``` * */