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.

Stronger type for Schema

See original GitHub issue

Hello, right now Schema type is defined as:

export interface Schema {
  /** `destinationProperty` is the name of the property of the target object you want to produce */
  [destinationProperty: string]: ActionString | ActionFunction | ActionAggregator | ActionSelector;
}

What do you think about changing it to:

export interface Schema<Target> {
  /** `destinationProperty` is the name of the property of the target object you want to produce */
  [destinationProperty in keyof Target]: ActionString | ActionFunction | ActionAggregator | ActionSelector;
}

It will enforce you to map all fields in the target type, so you won’t miss any of them by mistake.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
emyanncommented, Sep 25, 2018
screen shot 2018-09-25 at 4 28 07 pm
1reaction
emyanncommented, Sep 24, 2018

Hello @bossqone,

Thank you for this suggestion! In fact I was thinking about strengthening the link between the Schema and the Target type. Typescript interface does not accepts lookup in keys for index signature it will probably be

export type Schema<Target> = {
  /** `destinationProperty` is the name of the property of the target object you want to produce */
  [destinationProperty in keyof Target]?: ActionString | ActionFunction | ActionAggregator | ActionSelector
};

It will be like screen shot 2018-09-24 at 3 16 26 pm

I would prefer not to enforce the consumer to specify each property since Morphism will automatically map properties when a Class Type is provided.

class Foo {
  foo: string;
  bar: string;
}
const schema = { foo: 'qux' };
const source = { qux: 'foo', bar: 'bar' };
const fooInstance = morphism(schema, source, Foo);
// bar will be mapped from source even if it's not in the schema
// => { foo: 'foo', bar: 'bar' }

I just opened a PR here https://github.com/nobrainr/morphism/pull/34, what do you think about ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Types of Schema Markup in SEO: Picking the Right Structured ...
What are popular types of schema? Popular schema include: product markup, search action, FAQ schema, event schema, and more.
Read more >
Organization of Schemas
Schema.org is a set of extensible schemas that enables webmasters to embed ... The schemas are a set of 'types', each associated with...
Read more >
Multiple Types - JSON Schema
The basic declaration of multiple types is through the "type" keyword, ... This schema specifies both integers that are greater than or equal...
Read more >
Schema Evolution and Compatibility - Confluent Documentation
The compatibility type determines how Schema Registry compares the new schema with previous versions of a schema, for a given subject. When a...
Read more >
9 Most Common Schema Markup Types - Overdrive Interactive
Correspondingly, there are hundreds of markup types that can boost your ranking in search results.
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