Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error when using with react app #2

Closed
david-wb opened this issue Jun 3, 2020 · 0 comments
Closed

Runtime error when using with react app #2

david-wb opened this issue Jun 3, 2020 · 0 comments
Assignees

Comments

@david-wb
Copy link

david-wb commented Jun 3, 2020

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!

@moshegottlieb moshegottlieb self-assigned this Jun 4, 2020
@david-wb david-wb closed this as completed Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants