Skip to content

Commit

Permalink
ensure, that utility methods work with the returned adapter instance … (
Browse files Browse the repository at this point in the history
  • Loading branch information
foxriver76 authored Oct 12, 2023
1 parent 542faaa commit 64ad674
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ If you find errors in the definitions, e.g. function calls that should be allowe
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**
- (foxriver76) ensure, that utility methods work with the returned adapter instance on type level
### 3.0.3 (2023-07-30)
- (foxriver76) upgrade to new version of types package
Expand Down
2 changes: 1 addition & 1 deletion build/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export declare function getConfig(): Record<string, any>;
/**
* This type is used to include and exclude the states and objects cache from the adaptert type definition depending on the creation options
*/
export interface AdapterInstance<HasObjectsCache extends boolean | undefined = undefined, HasStatesCache extends boolean | undefined = undefined> extends Omit<ioBroker.Adapter, "oObjects" | "oStates"> {
export interface AdapterInstance<HasObjectsCache extends boolean | undefined = undefined, HasStatesCache extends boolean | undefined = undefined> extends ioBroker.Adapter {
oObjects: HasObjectsCache extends true ? Exclude<ioBroker.Adapter["oObjects"], undefined> : undefined;
oStates: HasStatesCache extends true ? Exclude<ioBroker.Adapter["oStates"], undefined> : undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function getConfig(): Record<string, any> {
export interface AdapterInstance<
HasObjectsCache extends boolean | undefined = undefined,
HasStatesCache extends boolean | undefined = undefined,
> extends Omit<ioBroker.Adapter, "oObjects" | "oStates"> {
> extends ioBroker.Adapter {
oObjects: HasObjectsCache extends true
? Exclude<ioBroker.Adapter["oObjects"], undefined>
: undefined;
Expand Down
11 changes: 9 additions & 2 deletions test/types/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
/* eslint-disable @typescript-eslint/class-name-casing */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as utils from "../../src/index";

const name = "foobar";
const options = { name };
const options = { name, objects: true } as const;

const adapter1 = utils.adapter(name);
const adapter2 = utils.Adapter(name);
Expand Down Expand Up @@ -36,4 +35,12 @@ class adapter11 extends utils.Adapter {
}
}

// default no objects cache
const res1: undefined = adapter1.oObjects;
// if objects given, with cache
const res2: Record<string, ioBroker.Object | undefined> = adapter5.oObjects;

// the created instance is accepted by the utility methods
utils.getAbsoluteInstanceDataDir(adapter1);

const code: number = utils.EXIT_CODES.ADAPTER_REQUESTED_TERMINATION;

0 comments on commit 64ad674

Please sign in to comment.