Skip to content

Commit

Permalink
Fixed LinkedDefinitions in @sap/cds
Browse files Browse the repository at this point in the history
  • Loading branch information
danjoa committed Aug 20, 2024
1 parent 46ca76a commit 920e22a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 27 deletions.
17 changes: 1 addition & 16 deletions apis/internal/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,8 @@ type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never }
/** @internal */
export type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U

// "ArrayLike" is taken since es5, so the underscore is both for @internal and to avoid clashes
/**
* A subset of array-like methods, but not `ArrayLike`, as it does not expose `.length`.
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#iterable)
* @internal
* @since cds 7.9
*/
export type _ArrayLike<T> = Iterable<T> & {
forEach: (handler: (element: T) => any) => void,
filter: (predicate: (element: T) => boolean) => Array<T>,
map: <R>(converter: (element: T) => R) => Array<R>,
some: (predicate: (element: T) => boolean) => boolean,
find: (predicate: (element: T) => boolean) => T | undefined,
}

/**
* Object structure that exposes both array-like and object-like behaviour.
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#iterable)
*/
export type IterableMap<T> = { [name: string]: T } & _ArrayLike<T>
export type IterableMap<T> = { [name: string]: T } & Iterable<T>
11 changes: 0 additions & 11 deletions test/typescript/apis/project/cds-linked.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LinkedCSN } from '../../../../apis/linked';
import { _ArrayLike } from '../../../../apis/internal/util';
import cds from '@sap/cds';
import { csn } from '../../../..';
import { as } from './dummy';
Expand Down Expand Up @@ -88,16 +87,6 @@ mixin(class {}, class {})
// @ts-expect-error
mixin(42)

const arr: _ArrayLike<number> = as<_ArrayLike<number>>()
// @ts-expect-error
arr.length
const v: void = arr.forEach(x => x + 1)
const s: string[] = arr.map(x => ''+x)
const xs: number[] = arr.filter(x => x > 0)
const x: number | undefined = arr.find(x => x > 0)
const b: boolean = arr.some(x => x > 0)
for (const n of arr) n + 1

// spot check to make sure linked classes are properly exposed cds.linked.classes...
cds.linked.classes.entity === entity
// @ts-expect-error
Expand Down

0 comments on commit 920e22a

Please sign in to comment.