Skip to content

Commit 886432f

Browse files
committed
Remove most remaining any usages and cleanup API
1 parent 73dab54 commit 886432f

25 files changed

+228
-357
lines changed

datacore.api.md

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ export class Canvas implements Linkable, File_2, Linkbearing, Taggable, Indexabl
137137
field(key: string): Field | undefined;
138138
// (undocumented)
139139
get fields(): Field[];
140+
// Warning: (ae-incompatible-release-tags) The symbol "from" is marked as @public, but its signature references "LinkNormalizer" which is marked as @internal
141+
//
140142
// (undocumented)
141143
static from(raw: JsonCanvas, normalizer?: LinkNormalizer): Canvas;
142144
// Warning: (ae-forgotten-export) The symbol "JsonCanvas" needs to be exported by the entry point index.d.ts
@@ -274,7 +276,9 @@ export function Checkbox(props: {
274276
children?: ComponentChildren;
275277
} & React_2.ComponentProps<"input">): React_2.JSX.Element;
276278

277-
// @public
279+
// Warning: (ae-internal-missing-underscore) The name "combineClasses" should be prefixed with an underscore because the declaration is marked as @internal
280+
//
281+
// @internal
278282
export function combineClasses(fixed: string, ...rest: (string | undefined)[]): string;
279283

280284
// @public
@@ -329,6 +333,7 @@ export namespace DataArray {
329333

330334
// @public
331335
export class Datacore extends Component {
336+
// Warning: (ae-incompatible-release-tags) The symbol "__constructor" is marked as @public, but its signature references "Settings" which is marked as @internal
332337
constructor(app: App, version: string, settings: Settings);
333338
// (undocumented)
334339
app: App;
@@ -363,6 +368,8 @@ export class Datacore extends Component {
363368
reads: EmbedQueue;
364369
reload(file: TFile): Promise<Indexable>;
365370
get revision(): number;
371+
// Warning: (ae-incompatible-release-tags) The symbol "settings" is marked as @public, but its signature references "Settings" which is marked as @internal
372+
//
366373
// (undocumented)
367374
settings: Settings;
368375
storeCanvas(data: Canvas): void;
@@ -497,7 +504,9 @@ export class DatacoreLocalApi {
497504
VanillaTable: typeof TableView;
498505
}
499506

500-
// @public
507+
// Warning: (ae-internal-missing-underscore) The name "DatacorePlugin" should be prefixed with an underscore because the declaration is marked as @internal
508+
//
509+
// @internal
501510
export class DatacorePlugin extends Plugin_2 {
502511
api: DatacoreApi;
503512
core: Datacore;
@@ -509,7 +518,10 @@ export class DatacorePlugin extends Plugin_2 {
509518
}
510519

511520
// @public
512-
export type DataObject = Record<string, any>;
521+
export interface DataObject {
522+
// (undocumented)
523+
[key: string]: Literal;
524+
}
513525

514526
// Warning: (ae-internal-missing-underscore) The name "Datastore" should be prefixed with an underscore because the declaration is marked as @internal
515527
//
@@ -577,7 +589,7 @@ export namespace Expressions {
577589
export namespace Extractors {
578590
export function frontmatter<T extends Indexable>(front: (object: T) => Record<string, FrontmatterEntry> | undefined): FieldExtractor<T>;
579591
export function inlineFields<T extends Indexable>(inlineMap: (object: T) => Record<string, InlineField> | undefined): FieldExtractor<T>;
580-
export function intrinsics<T extends Record<string, any>>(except?: Set<string>): FieldExtractor<T>;
592+
export function intrinsics<T>(except?: Set<string>): FieldExtractor<T>;
581593
export function merge<T extends Fieldbearing>(...extractors: FieldExtractor<T>[]): FieldExtractor<T>;
582594
}
583595

@@ -589,6 +601,8 @@ export class Failure<T, E> {
589601
// (undocumented)
590602
cast<U>(): Result<U, E>;
591603
// (undocumented)
604+
castErr<U>(): Result<T, U>;
605+
// (undocumented)
592606
error: E;
593607
// (undocumented)
594608
flatMap<U>(_f: (a: T) => Result<U, E>): Result<U, E>;
@@ -623,9 +637,9 @@ export const FIELDBEARING_TYPE = "fields";
623637

624638
// @public (undocumented)
625639
export namespace Fieldbearings {
626-
export function get(object: Fieldbearing | Record<string, Literal>, key: string): Literal | undefined;
640+
export function get(object: Fieldbearing | DataObject, key: string): Literal | undefined;
627641
// (undocumented)
628-
export function isFieldbearing(object: any): object is Fieldbearing;
642+
export function isFieldbearing(object: unknown): object is Fieldbearing;
629643
}
630644

631645
// @public
@@ -662,7 +676,7 @@ export interface FunctionExpression {
662676
// Warning: (ae-internal-missing-underscore) The name "gatherLinks" should be prefixed with an underscore because the declaration is marked as @internal
663677
//
664678
// @internal
665-
export function gatherLinks(input: Literal): Link[];
679+
export function gatherLinks(input: unknown): Link[];
666680

667681
// Warning: (ae-internal-missing-underscore) The name "gatherTags" should be prefixed with an underscore because the declaration is marked as @internal
668682
//
@@ -714,7 +728,7 @@ export type Grouping<T> = T[] | GroupElement<T>[];
714728
// @public (undocumented)
715729
export namespace Groupings {
716730
export function count<T>(elements: Grouping<T> | GroupElement<T>): number;
717-
export function isElementGroup<T>(entry: any): entry is GroupElement<T>;
731+
export function isElementGroup<T>(entry: unknown): entry is GroupElement<T>;
718732
export function isGrouping<T>(entry: Grouping<T>): entry is GroupElement<T>[];
719733
export function isLeaf<T>(entry: Grouping<T>): entry is T[];
720734
export function slice<T>(elements: Grouping<T>, start: number, end: number): Grouping<T>;
@@ -909,7 +923,9 @@ export interface InlineField {
909923
// @public
910924
export type Intent = "error" | "warn" | "info" | "success";
911925

912-
// @public
926+
// Warning: (ae-internal-missing-underscore) The name "INTENT_CLASSES" should be prefixed with an underscore because the declaration is marked as @internal
927+
//
928+
// @internal
913929
export const INTENT_CLASSES: Record<Intent, string>;
914930

915931
// Warning: (ae-forgotten-export) The symbol "JsonFrontmatterEntry" needs to be exported by the entry point index.d.ts
@@ -973,7 +989,9 @@ export interface Linkbearing {
973989
// @public
974990
export const LINKBEARING_TYPE = "links";
975991

976-
// @public
992+
// Warning: (ae-internal-missing-underscore) The name "LinkNormalizer" should be prefixed with an underscore because the declaration is marked as @internal
993+
//
994+
// @internal
977995
export type LinkNormalizer = (link: Link) => Link;
978996

979997
// @public
@@ -1004,8 +1022,9 @@ export interface ListViewProps<T> {
10041022
export type ListViewType = "ordered" | "unordered" | "block";
10051023

10061024
// Warning: (ae-forgotten-export) The symbol "RawLit" needs to be exported by the entry point index.d.ts
1025+
// Warning: (ae-internal-missing-underscore) The name "Lit" should be prefixed with an underscore because the declaration is marked as @internal
10071026
//
1008-
// @public
1027+
// @internal
10091028
export const Lit: typeof RawLit;
10101029

10111030
// @public
@@ -1020,34 +1039,34 @@ export interface LiteralExpression {
10201039
}
10211040

10221041
// @public
1023-
export type LiteralRepr<T extends LiteralType> = T extends "boolean" ? boolean : T extends "number" ? number : T extends "string" ? string : T extends "duration" ? Duration : T extends "date" ? DateTime : T extends "null" ? null : T extends "link" ? Link : T extends "array" ? Array<Literal> : T extends "object" ? DataObject : T extends "function" ? Function : any;
1042+
export type LiteralRepr<T extends LiteralType> = T extends "boolean" ? boolean : T extends "number" ? number : T extends "string" ? string : T extends "duration" ? Duration : T extends "date" ? DateTime : T extends "null" ? null : T extends "link" ? Link : T extends "array" ? Array<Literal> : T extends "object" ? DataObject : T extends "function" ? Function : unknown;
10241043

10251044
// @public
10261045
export namespace Literals {
10271046
export function compare(val1: Literal | undefined, val2: Literal | undefined, linkNormalizer?: (link: string) => string): number;
10281047
const DEFAULT_TO_STRING: ToStringSettings;
10291048
export function deepCopy<T extends Literal>(field: T): T;
10301049
export function equals(first: Literal | undefined, second: Literal | undefined): boolean;
1031-
export function isArray(val: any): val is any[];
1032-
export function isBoolean(val: any): val is boolean;
1033-
export function isDate(val: any): val is DateTime;
1034-
export function isDuration(val: any): val is Duration;
1035-
export function isFunction(val: any): val is Function;
1036-
export function isLink(val: any): val is Link;
1037-
export function isNull(val: any): val is null | undefined;
1038-
export function isNumber(val: any): val is number;
1039-
export function isObject(val: any): val is Record<string, any>;
1040-
export function isString(val: any): val is string;
1050+
export function isArray(val: unknown): val is unknown[];
1051+
export function isBoolean(val: unknown): val is boolean;
1052+
export function isDate(val: unknown): val is DateTime;
1053+
export function isDuration(val: unknown): val is Duration;
1054+
export function isFunction(val: unknown): val is Function;
1055+
export function isLink(val: unknown): val is Link;
1056+
export function isNull(val: unknown): val is null | undefined;
1057+
export function isNumber(val: unknown): val is number;
1058+
export function isObject(val: unknown): val is DataObject;
1059+
export function isString(val: unknown): val is string;
10411060
export function isTruthy(field: Literal): boolean;
10421061
export function mapLeaves(val: Literal, func: (t: Literal) => Literal): Literal;
1043-
export function toString(field: any, setting?: ToStringSettings, recursive?: boolean): string;
1062+
export function toString(field: unknown, setting?: ToStringSettings, recursive?: boolean): string;
10441063
export interface ToStringSettings {
10451064
dateFormat: string;
10461065
dateTimeFormat: string;
10471066
nullRepresentation: string;
10481067
}
1049-
export function typeOf(val: any): LiteralType | undefined;
1050-
export function wrapValue(val: Literal): WrappedLiteral | undefined;
1068+
export function typeOf(val: unknown): LiteralType | undefined;
1069+
export function wrapValue(val: unknown): WrappedLiteral | undefined;
10511070
}
10521071

10531072
// @public
@@ -1071,8 +1090,9 @@ export type LowestKey<T> = T extends {
10711090
} ? LowestKey<T["rows"][0]> : T;
10721091

10731092
// Warning: (ae-forgotten-export) The symbol "RawMarkdown" needs to be exported by the entry point index.d.ts
1093+
// Warning: (ae-internal-missing-underscore) The name "Markdown" should be prefixed with an underscore because the declaration is marked as @internal
10741094
//
1075-
// @public
1095+
// @internal
10761096
export const Markdown: typeof RawMarkdown;
10771097

10781098
// @public
@@ -1261,7 +1281,7 @@ export class MarkdownPage implements File_2, Linkbearing, Taggable, Indexable, F
12611281
value(key: string): Literal | undefined;
12621282
}
12631283

1264-
// @public (undocumented)
1284+
// @public
12651285
export class MarkdownSection implements Indexable, Taggable, Linkable, Linkbearing, Fieldbearing {
12661286
$blocks: MarkdownBlock[];
12671287
// (undocumented)
@@ -1330,13 +1350,15 @@ export interface NegatedExpression {
13301350
type: "negated";
13311351
}
13321352

1333-
// @public (undocumented)
1353+
// Warning: (ae-internal-missing-underscore) The name "NOOP_NORMALIZER" should be prefixed with an underscore because the declaration is marked as @internal
1354+
//
1355+
// @internal
13341356
export const NOOP_NORMALIZER: LinkNormalizer;
13351357

13361358
// Warning: (ae-internal-missing-underscore) The name "normalizeLinks" should be prefixed with an underscore because the declaration is marked as @internal
13371359
//
13381360
// @internal
1339-
export function normalizeLinks<T extends Literal>(input: T, normalizer: LinkNormalizer): T;
1361+
export function normalizeLinks<T>(input: T, normalizer: LinkNormalizer): T;
13401362

13411363
// @public
13421364
export interface ObjectExpression {
@@ -1380,7 +1402,9 @@ export interface SearchResult<O> {
13801402
revision: number;
13811403
}
13821404

1383-
// @public
1405+
// Warning: (ae-internal-missing-underscore) The name "Settings" should be prefixed with an underscore because the declaration is marked as @internal
1406+
//
1407+
// @internal
13841408
export interface Settings {
13851409
defaultDateFormat: string;
13861410
defaultDateTimeFormat: string;
@@ -1423,6 +1447,8 @@ export class Success<T, E> {
14231447
// (undocumented)
14241448
cast<U>(): Result<U, E>;
14251449
// (undocumented)
1450+
castErr<U>(): Result<T, U>;
1451+
// (undocumented)
14261452
flatMap<U>(f: (a: T) => Result<U, E>): Result<U, E>;
14271453
// (undocumented)
14281454
map<U>(f: (a: T) => U): Result<U, E>;

src/api/data-array.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export interface DataArray<T> {
7777

7878
/**
7979
* Return an array where elements are grouped by the given key; the resulting array will have objects of the form
80-
* \`{ key: \<key value\>, rows: DataArray }`.
80+
* `\{ key: \<key value\>, rows: DataArray \}`.
8181
*/
8282
groupBy<U>(key: ArrayFunc<T, U>, comparator?: ArrayComparator<U>): DataArray<{ key: U; rows: T[] }>;
8383

@@ -364,7 +364,7 @@ class DataArrayImpl<T> implements DataArray<T> {
364364

365365
public distinct<U>(key?: ArrayFunc<T, U>, comparator?: ArrayComparator<U>): DataArray<T> {
366366
if (this.values.length == 0) return this;
367-
let realKey = key ?? ((x) => x as any as U);
367+
let realKey = key ?? ((x) => x as unknown as U);
368368

369369
// For similar reasons to groupBy, do a sort and take the first element of each block.
370370
let intermediate = this.map((x, index) => {

src/api/local-api.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ import { ListView } from "./ui/views/list";
3434
* @public
3535
*/
3636
export class DatacoreLocalApi {
37-
/**
38-
* The cache of all currently loaded scripts in this context.
39-
* @private
40-
* @internal
41-
*/
37+
/** @internal The cache of all currently loaded scripts in this context. */
4238
private scriptCache: ScriptCache;
4339

4440
public constructor(public api: DatacoreApi, public path: string) {

src/api/result.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
/**
2-
* @module api
3-
*/
4-
/**
5-
* Functional return type for error handling.
6-
* @hidden
7-
* */
1+
/** @public Functional return type for error handling. */
82
export class Success<T, E> {
93
public successful: true;
104

@@ -21,29 +15,31 @@ export class Success<T, E> {
2115
}
2216

2317
public mapErr<U>(f: (e: E) => U): Result<T, U> {
24-
return this as any as Result<T, U>;
18+
return this.castErr();
2519
}
2620

2721
public bimap<T2, E2>(succ: (a: T) => T2, _fail: (b: E) => E2): Result<T2, E2> {
28-
return this.map(succ) as any;
22+
return this.map(succ).castErr();
2923
}
3024

3125
public orElse(_value: T): T {
3226
return this.value;
3327
}
3428

3529
public cast<U>(): Result<U, E> {
36-
return this as any;
30+
return this as unknown as Result<U, E>;
31+
}
32+
33+
public castErr<U>(): Result<T, U> {
34+
return this as unknown as Result<T, U>;
3735
}
3836

3937
public orElseThrow(_message?: (e: E) => string): T {
4038
return this.value;
4139
}
4240
}
4341

44-
/** Functional return type for error handling.
45-
* @hidden
46-
*/
42+
/** @public Functional return type for error handling. */
4743
export class Failure<T, E> {
4844
public successful: false;
4945

@@ -52,27 +48,31 @@ export class Failure<T, E> {
5248
}
5349

5450
public map<U>(_f: (a: T) => U): Result<U, E> {
55-
return this as any as Failure<U, E>;
51+
return this.cast();
5652
}
5753

5854
public flatMap<U>(_f: (a: T) => Result<U, E>): Result<U, E> {
59-
return this as any as Failure<U, E>;
55+
return this.cast();
6056
}
6157

6258
public mapErr<U>(f: (e: E) => U): Result<T, U> {
6359
return new Failure(f(this.error));
6460
}
6561

6662
public bimap<T2, E2>(_succ: (a: T) => T2, fail: (b: E) => E2): Result<T2, E2> {
67-
return this.mapErr(fail) as any;
63+
return this.mapErr(fail).cast();
6864
}
6965

7066
public orElse(value: T): T {
7167
return value;
7268
}
7369

7470
public cast<U>(): Result<U, E> {
75-
return this as any;
71+
return this as unknown as Result<U, E>;
72+
}
73+
74+
public castErr<U>(): Result<T, U> {
75+
return this as unknown as Result<T, U>;
7676
}
7777

7878
public orElseThrow(message?: (e: E) => string): T {
@@ -82,15 +82,13 @@ export class Failure<T, E> {
8282
}
8383

8484
/**
85+
* @public
8586
* A monadic result type which stores either "success" or "failure". An alternative handling exceptional behavior
8687
* by using the return value instead of an exception.
8788
*/
8889
export type Result<T, E> = Success<T, E> | Failure<T, E>;
8990

90-
/**
91-
* @hidden
92-
* Monadic 'Result' type which encapsulates whether a procedure succeeded or failed, as well as it's return value.
93-
*/
91+
/** @public Monadic 'Result' type which encapsulates whether a procedure succeeded or failed, as well as it's return value. */
9492
export namespace Result {
9593
/** Construct a new success result wrapping the given value. */
9694
export function success<T, E>(value: T): Result<T, E> {

0 commit comments

Comments
 (0)