Open fgnm opened 1 year ago
Describe the bug I'm using total in a TypeScript project. Types are fine except for the custom functions in prototype of String, Number, Date, and Array defined here: https://github.com/totaljs/framework4/blob/f9c5f2a452d9fd159fda56389bc9139a292a68bb/index.d.ts#L294-L397
String
Number
Date
Array
Basically VS Code says that for example the function last in an Array doesn't exists... After a while I've discovered that if a move all the interface declaration inside the declare global block it works:
last
declare global
declare global { interface Array<T> { async: (threadCount?: number, onComplete?: () => void) => T; findAll: (fn: (item: any, next: () => void) => void) => T; findItem: (fn: (item: any, next: () => void) => void) => any; findValue: (prop: string, value: object, path: string, def?: object) => any; first: (def?: object) => any; last: (def?: object) => any; limit: (max: number, fn: (items: any, next: () => void) => void, callback?: () => void) => T; quicksort: (path: string, asc: boolean | string) => T; random: () => T; remove: (fn: (item: any, index: any) => void) => T; skip: (count: number) => T; take: (count: number) => T; toObject: (name?: string) => any; trim: () => T; wait: (onItem: (item: any, next: () => void) => void, callback?: () => void, threadCount?: number) => T; } interface String { arg: (obj: object, encode?: boolean | string, def?: string) => string; bae64ContentType: () => string; bae64ToBuffer: () => string; bae64ToFile: (filename: string, callback?: (err: any) => void) => string; capitalize: (first?: boolean) => string; count: (word: string) => string; crc32: (unsigned?: boolean) => string; decode: () => string; decrypt_uid: (secret?: string) => string; decrpyt: (key: string, secret?: string) => string; encode: () => string; encrypt_uid: (secret?: string) => string; encrpyt: (key: string, unique: boolean, secret?: string) => string; format: (param1?: string, param2?: string, param3?: string, param4?: string, param5?: string) => string; fromUnicode: () => string; hash: (type?: string, salt?: string) => string; isBase64: () => boolean; isBoolean: () => boolean; isEmail: () => boolean; isJSON: () => boolean; isPhone: () => boolean; isUID: () => boolean; isURL: () => boolean; isZIP: () => boolean; keywords: (forSearch?: boolean, alternative?: boolean | string, max_count?: number, max_lenght?: number, min_length?: number) => string[]; makeid: () => string; max: (maxLenght: number, chars?: string) => string; md5: (salt?: string) => string; padLeft: (max: number, char?: string) => string; padRight: (max: number, char?: string) => string; params: (obj: object) => string; parseBool: () => boolean; parseComponent: (tags: object) => any; parseCSV: (delimeter?: string) => any[]; parseDate: () => Date; parseDateExpiration: () => Date; parseENV: () => any; parseFloat: (def?: object) => number; parseFloat2: (def?: object) => number; parseInt: (def?: object) => number; parseInt2: (def?: object) => number; parseJSON: () => object; parseQuery: () => object; parseTerminal: (fields: string[], fnLine: (values: any, index: any, count: any, realIndex: any) => void, skipLines?: number, takeLines?: number) => object; parseUA: (structured?: boolean) => string | object; parseXML: (replace?: boolean) => object; pluralize: (zero: string, one: string, few: string, other: string) => string; removeTags: () => string; ROOT: (noremap?: boolean) => string; sha1: (salt?: string) => string; sha256: (salt?: string) => string; sha512: (salt?: string) => string; slug: (max?: number) => string; startWith: (value: string, ignoreCase?: boolean) => boolean; toASCII: () => string; toSearch: () => string; toUnicode: () => string; trim: () => string; } interface Number { add: (value: number, decimals?: number) => number; async: (onNumber: (number: number, mext: () => void) => void, onComplete: () => void) => number; between: (condition: object, otherwise: object) => number; currency: (currency: string) => string; discount: (percentage: number, decimals?: number) => number; filesize: (decimals?: number, type?: string) => string; floor: (decimals?: number) => number; format: (decimals?: number, separator?: string, decimalSeparator?: string) => string; hex: (length: number) => string; padLeft: (max: number, char?: string) => string; padRight: (max: number, char?: string) => string; parseDate: (plus?: number) => number; pluralize: (zero: string, one: string, few: string, other: string) => string; VAT: (percentage: number, decimals?: number, includeVAT?: boolean) => number; round: (decimals?: number) => number; } interface Date { add: (expression: string | number) => Date; extend: (type: string, count: number) => Date; format: (format?: string, resource?: string) => string; setTimeZone: (timezone: string) => Date; toUTC: (ticks?: boolean) => Date | number; } function SUCCESS(): SUCCESS; type SUCCESS = (success?: boolean, value?: any) => { success: boolean, error: any, value: any}; type DEF = { onAudit: (name: string, data: object) => void; onCompileScript: (filename: string, body: string) => void; onCompileStyle: (name: string, body: string) => void; onCompileView: (name: string, html: string) => void; onPrefLoad: (next: (pref_obj: object) => void) => void; onPrefSave: (PREF: object) => void; } ......
I don't know why exactly I got this issue, but I thought might be good to report. This is my tsconfig.json
tsconfig.json
{ "compilerOptions": { "target": "es2020", "module": "commonjs", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "strictPropertyInitialization": false, "types": ["total4", "@types/node"], "noImplicitThis": false } }
Must gather (please complete the following information):
Sorry, but we need to find someone who uses TypeScript :/ ... We don't use it.
Describe the bug I'm using total in a TypeScript project. Types are fine except for the custom functions in prototype of
String
,Number
,Date
, andArray
defined here: https://github.com/totaljs/framework4/blob/f9c5f2a452d9fd159fda56389bc9139a292a68bb/index.d.ts#L294-L397Basically VS Code says that for example the function
last
in an Array doesn't exists... After a while I've discovered that if a move all the interface declaration inside thedeclare global
block it works:I don't know why exactly I got this issue, but I thought might be good to report. This is my
tsconfig.json
Must gather (please complete the following information):