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

Fixed LinkedDefinitions in @sap/cds #204

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
daogrady marked this conversation as resolved.
Show resolved Hide resolved
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
Loading