Skip to content

Latest commit

 

History

History
66 lines (54 loc) · 1.82 KB

schema-class-object-literal.md

File metadata and controls

66 lines (54 loc) · 1.82 KB

schemaClassObjectLiteral

Warns when object literals are checked as Schema class instances without the class prototype

Property Value
Category Correctness
Default severity warning
Fixable No
Effect versions v3, v4
Diagnostic codes TS377149
Language Service name schemaClassObjectLiteral
Oxlint name effecttsgo/schema-class-object-literal

Preview

import { Schema } from "effect"

export class User extends Schema.Class<User, { readonly brand: unique symbol }>("User")({ name: Schema.String }) {}
export const user = User.make({ name: "a" })
export const copy: User = { ...user }
/**
                          ^^^^^^^^^^^ effecttsgo(schema-class-object-literal): This object literal is checked as an instance of Schema class 'User' but has no class prototype. instanceof checks, methods, and Schema encoding can fail. Use 'User.make(...)' or 'new User(...)' instead.
*/
export const renamed = User.make({ ...user, name: "b" })

Language Service Configuration

See the Language Service setup guide for installation instructions.

{
  "$schema": "./node_modules/@effect/tsgo/schema.json",
  "compilerOptions": {
    "plugins": [
      {
        "name": "@effect/language-service",
        "diagnosticSeverity": {
          "schemaClassObjectLiteral": "warning"
        }
      }
    ]
  }
}

Oxlint Configuration

See the Oxlint setup guide for installation and patching instructions.

{
  "$schema": "./node_modules/@effect/tsgo/oxlint-schema.json",
  "options": {
    "typeAware": true
  },
  "plugins": ["effecttsgo"],
  "rules": {
    "effecttsgo/schema-class-object-literal": "warn"
  }
}