effect icon indicating copy to clipboard operation
effect copied to clipboard

Abstract class properties are swallowed when using `Class.extend` from Schema

Open Avaq opened this issue 1 year ago • 0 comments

What version of Effect is running?

3.9.1

What steps can reproduce the bug?

  1. Run

    npm i @effect/[email protected] typescript @tsconfig/strictest
    
  2. Create tsconfig.json:

    {
      "extends": "@tsconfig/strictest/tsconfig.json",
      "include": ["index.ts"],
      "compilerOptions": {"module": "commonjs", "target": "ES2015", "noEmit": true}
    }
    
  3. Create index.ts:

    import {Schema as S} from '@effect/schema'
    
    abstract class Human extends S.Class<Human>('Human')({ name: S.String }) {
      abstract title: string;
      get fullname(){ return `${this.title} ${this.name}` }
    }
    
    class Doctor extends Human.extend<Doctor>('Doctor')({ speciality: S.String }) {
      // It should not be possible to omit the following line:
      // title = "Dr."
    }
    
    console.log(new Doctor({name: 'Phil', speciality: 'Psychology'}).fullname)
    
  4. Run

    ./node_modules/.bin/tsc -p tsconfig.json
    

What is the expected behavior?

TypeScript should catch the fact that I haven't implemented title in my sub-class, as required by the parent class Human, and print an error.

What do you see instead?

No error is printed. The program compiles, and when run prints "undefined Phil" to the console, as a result of the runtime type error.

Additional information

It seems that Human.extend() returns a class that pretends to implement title, but really doesn't.

Avaq avatar Oct 08 '24 10:10 Avaq