question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

union types in nested objects causes error [BUG]

See original GitHub issue

Summary:

I tried to create a schema with union types in a nested object.

Code sample:

Schema

const NestedObjectWithUnionType = {
  type: Object,
  schema: {
    attribute1: [String, Boolean, Number],
    attribute2: String,
  },
};

const MyModel = dynamoose.model(
  `test`,
  new dynamoose.Schema({
    exampleId: {
      type: String,
      hashKey: true,
    },
    name: String,
    myNestedObject: NestedObjectWithUnionType,
  })
);

Current output and behavior (including stack trace):

InvalidParameter: Index must be at root object and not nested in object or array.
  at node_modules/dynamoose/lib/Schema.ts:587:11
      at Array.forEach (<anonymous>)
  at new Schema (node_modules/dynamoose/lib/Schema.ts:585:21)
  at Object.<anonymous> (src/example.ts:648:102)
  at Object.<anonymous> (src/example.ts:1456:27)

Environment:

Operating System: macOS Operating System Version: Sierra Node.js version (node -v): 14.8.0 NPM version: (npm -v): 6.14.5 Dynamoose version: 2.5.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
fishcharliecommented, Jan 28, 2021

@julada Oh maybe the problem is that this was fixed in #985. Just hasn’t been released yet. Still doesn’t completely explain why I couldn’t reproduce it. Maybe NPM was caching a local version?? A new release with this fix should be coming out soon.

1reaction
fishcharliecommented, Jan 27, 2021

@julada I ran the following code (just like in your original post).

const dynamoose = require("dynamoose");
dynamoose.aws.ddb.local();

const NestedObjectWithUnionType = {
	type: Object,
	schema: {
	  attribute1: [String, Boolean, Number],
	  attribute2: String,
	},
  };

  const MyModel = dynamoose.model(
	`test`,
	new dynamoose.Schema({
	  exampleId: {
		type: String,
		hashKey: true,
	  },
	  name: String,
	  myNestedObject: NestedObjectWithUnionType,
	})
  );

And got this as the result:

charliefish tmp4 % node index.js
charliefish tmp4 % 

As you can see, no error, no problem. It ran successfully.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript union of nested type loses key that isn't shared ...
Object types in TypeScript are extendible via adding of properties, due to structural subtyping. And so the compiler decides to infer just X ......
Read more >
Bug: nested object lose intellisense when defined in union ...
Since we have a structural type system, we can't tell just by looking at an interface whether it's meant to be implemented by...
Read more >
Types - Julia Documentation
It is the exact opposite of Any : no object is an instance of Union{} and all types are supertypes of Union{} ....
Read more >
Structs, Unions - D Programming Language
A struct or union is Plain Old Data (POD) if it meets the following criteria: it is not nested; it has no postblits,...
Read more >
Mastering TypeScript mapped types - LogRocket Blog
In this post, we'll cover mapped types in TypeScript, a real-world example of them, ... A union type is a combination of two...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found