Skip to content

Runtime error when using with react app #2

Closed
@david-wb

Description

@david-wb

I'm seeing this error on the default example when running inside a react app.

    json_object.ts:60 Uncaught TypeError: Cannot read property 'name' of undefined
    at Book.newValue (json_object.ts:60)
    at Book.set (json_object.ts:85)
    at new JSONObject (json_object.ts:157)
    at new Book (json-models.ts:46)

Here is the code.


class Book extends JSONObject {
    @JSONObject.required
    // @ts-ignore
	name:string
    @JSONObject.optional
    // @ts-ignore
	summary?:string
}

// This is ok
let book:Book = new Book({ name: "Moby Dick" , summary: "You're my obsession" })

And here is my tsconfig

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "plugins": [{ "name": "typescript-tslint-plugin" }],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "sourceMap": true,
    "jsx": "react"
  },
  "include": ["src"]
}

Any idea what the problem might be here? Thanks!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions