Play nice with @types/iobroker, rename a bunch of stuff and rework the methods #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@gaudes Don't be shocked - I think almost every line has changed in some way. Here's a breakdown of what I did:
Use a consequent naming scheme:
ObjectCommonSchema
camelCase
Give things names that better describe what they do:
XyzSchema
describes how objects look likeCommonAttribute
in the nameTemplateObjectDefinition
ObjectWithValue
buildObject
syncObjects
Make the definitions and predefined object templates validate themselves
I had to get a bit creative with the types here, but basically the exported objects are now passed through a function which is only used to validate the types. This lets us detect typos, whether attributes are used that are not present in the type definitions (most likely bugs in the type definitions):
or if something is even missing from those objects (like a
CommonSchema
for theinfo
object type).Use the bag-of-objects convention instead of overloads
I had to learn this the hard way while writing zwave-js, but using multiple overloads of a function with very different parameters is insanely annoying and error prone in JavaScript / TypeScript, as you can see from your attempt with
...any[]
. Also you never know by looking at a function call what it does:By defining an options type, e.g.
we can have a single object parameter with optional properties that can depend on the value of other properties and have TypeScript yell at us if we messed up a parameter combination. Plus you know immediately what each value stands for:
and you also don't need
args[5]
(what was that again?) in the implementation.