{"record":{"id":"bdae42307702223e","repo":"apple/pkl","slug":"type-mismatch-value-is-not-of-type-typed","errorCode":null,"errorMessage":"type mismatch: value is not of type Typed","messagePattern":"type mismatch: value is not of type Typed","errorType":"exception","errorClass":"VmTypeMismatchException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java","lineNumber":649,"sourceCode":"      return new PType.StringLiteral(literal);\n    }\n\n    @Override\n    protected boolean acceptTypeNode(boolean visitTypeArguments, TypeNodeConsumer consumer) {\n      return consumer.accept(this);\n    }\n  }\n\n  public static final class TypedTypeNode extends ObjectSlotTypeNode {\n    public TypedTypeNode(SourceSection sourceSection) {\n      super(sourceSection);\n    }\n\n    @Override\n    protected Object executeLazily(VirtualFrame frame, Object value) {\n      if (value instanceof VmTyped) return value;\n\n      throw typeMismatch(value, BaseModule.getTypedClass());\n    }\n\n    @Override\n    public VmClass getVmClass() {\n      return BaseModule.getTypedClass();\n    }\n\n    @Override\n    public boolean doIsEquivalentTo(TypeNode other) {\n      return other instanceof TypedTypeNode;\n    }\n\n    @Override\n    protected boolean acceptTypeNode(boolean visitTypeArguments, TypeNodeConsumer consumer) {\n      return consumer.accept(this);\n    }\n  }\n","sourceCodeStart":631,"sourceCodeEnd":667,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L631-L667","documentation":"Pkl `Typed` type check failure. The `Typed` type is the base type of all class instances created with `new`; the check (`value instanceof VmTyped`) rejects anything else. The value was expected to be a Typed (class-instance) object but was a Dynamic, Listing, Mapping, primitive, function, etc.","triggerScenarios":"Declaring a property as `Typed` and assigning a Dynamic object (`new Dynamic {}`), a primitive, a collection, or null; passing a non-class-instance into an API expecting `Typed`.","commonSituations":"Migrating code from `Dynamic` to typed classes and forgetting to convert `new Dynamic {...}` to `new SomeClass {...}`; returning an object literal where a class instance is required; null default where Typed has no default.","solutions":["Replace the value with a class instance created via `new SomeClass { ... }`.","If any object is acceptable, change the declared type from `Typed` to `Dynamic` or `Object`.","If the value is currently a Dynamic, convert it: define a class and construct with `new`.","Check for accidental assignment of a Listing/Mapping, which is not `Typed`."],"exampleFix":"// before\nobj: Typed = new Dynamic { name = \"x\" }\n// after\nobj: Typed = new Person { name = \"x\" }","handlingStrategy":"type-guard","validationCode":"// Pkl\nif (value is Typed) {\n  obj: Typed = value\n}","typeGuard":"function isTypedObject(value: Any): Boolean = value is Typed","tryCatchPattern":"// Guard with `is Typed` before assignment; embedders: catch PklException filtered on 'not of type Typed'.","preventionTips":["Remember Dynamic/List/Mapping/primitives are not `Typed`","Construct class instances with `new`, not object literals","Declare the narrowest accurate type instead of `Typed` when possible"],"tags":["pkl","type-mismatch","typed","typecheck"],"backgroundTag":"type-mismatch","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}