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

ensure, that utility methods work with the returned adapter instance … #575

Merged
merged 1 commit into from Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
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
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
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
@@ -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 @@
}
}

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

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

const code: number = utils.EXIT_CODES.ADAPTER_REQUESTED_TERMINATION;