effect
effect copied to clipboard
Abstract class properties are swallowed when using `Class.extend` from Schema
What version of Effect is running?
3.9.1
What steps can reproduce the bug?
-
Run
npm i @effect/[email protected] typescript @tsconfig/strictest -
Create
tsconfig.json:{ "extends": "@tsconfig/strictest/tsconfig.json", "include": ["index.ts"], "compilerOptions": {"module": "commonjs", "target": "ES2015", "noEmit": true} } -
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) -
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.