diff --git a/package.json b/package.json index d985e39d01..c5b1b03057 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "scripts": { "compile-scripts": "tsc -p scripts", "not-needed": "node scripts/not-needed.js", - "test": "node node_modules/types-publisher/bin/tester/test.js --run-from-definitely-typed --nProcesses 2", + "test": "node node_modules/types-publisher/bin/tester/test.js --run-from-definitely-typed", "lint": "dtslint types" }, "devDependencies": { diff --git a/types/facebook-js-sdk/facebook-js-sdk-tests.ts b/types/facebook-js-sdk/facebook-js-sdk-tests.ts index 9652dbb86f..6b400a10a7 100644 --- a/types/facebook-js-sdk/facebook-js-sdk-tests.ts +++ b/types/facebook-js-sdk/facebook-js-sdk-tests.ts @@ -8,25 +8,22 @@ FB.init({ xfbml: true }); -FB.getLoginStatus(function(response: fb.AuthResponse) { +FB.getLoginStatus(function(response: fb.StatusResponse) { console.log(response); console.log(response.status); console.log(response.authResponse.accessToken); }); -FB.getLoginStatus(function(response: fb.AuthResponse) { +FB.getLoginStatus(function(response: fb.StatusResponse) { console.log(response); console.log(response.status); console.log(response.authResponse.accessToken); }, true); -FB.getAuthResponse(function(response: fb.AuthResponse) { - console.log(response); - console.log(response.status); - console.log(response.authResponse.accessToken); -}); +const authResponse: fb.AuthResponse = FB.getAuthResponse(); +console.log(authResponse.accessToken); -FB.login(function(response: fb.AuthResponse) { +FB.login(function(response: fb.StatusResponse) { console.log(response); console.log(response.status); console.log(response.authResponse.accessToken); @@ -34,7 +31,7 @@ FB.login(function(response: fb.AuthResponse) { scope: 'public_profile' }); -FB.logout(function(response: fb.AuthResponse) { +FB.logout(function(response: fb.StatusResponse) { console.log(response); console.log(response.status); console.log(response.authResponse.accessToken); diff --git a/types/facebook-js-sdk/index.d.ts b/types/facebook-js-sdk/index.d.ts index be9f71f6c9..69f7fbb08d 100644 --- a/types/facebook-js-sdk/index.d.ts +++ b/types/facebook-js-sdk/index.d.ts @@ -1,12 +1,14 @@ // Type definitions for the Facebook Javascript SDK 2.8 // Project: https://developers.facebook.com/docs/javascript -// Definitions by: Amrit Kahlon +// Definitions by: Amrit Kahlon +// Mahmoud Zohdi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped import fb = facebook; declare var FB: fb.FacebookStatic; declare namespace facebook { - + + interface FacebookStatic { api: any; AppEvents: any; @@ -18,15 +20,17 @@ declare namespace facebook { * The synchronous nature of this method is what sets it apart from the other login methods. * * @param callback function to handle the response. + * + * This method is similar in nature to FB.getLoginStatus(), but it returns just the authResponse object. */ - getAuthResponse(callback: (response: AuthResponse) => void): void; + getAuthResponse(): AuthResponse; /** * FB.getLoginStatus() allows you to determine if a user is * logged in to Facebook and has authenticated your app. * * @param callback function to handle the response. */ - getLoginStatus(callback: (response: AuthResponse) => void, roundtrip?: boolean ): void; + getLoginStatus(callback: (response: StatusResponse) => void, roundtrip?: boolean ): void; /** * The method FB.init() is used to initialize and setup the SDK. * @@ -43,13 +47,13 @@ declare namespace facebook { * @param callback function to handle the response. * @param options optional ILoginOption to add params such as scope. */ - login(callback: (response: AuthResponse) => void, options?: LoginOptions): void; + login(callback: (response: StatusResponse) => void, options?: LoginOptions): void; /** * The method FB.logout() logs the user out of your site and, in some cases, Facebook. * * @param callback function to handle the response */ - logout(callback: (response: AuthResponse) => void): void; + logout(callback: (response: StatusResponse) => void): void; /** * @see https://developers.facebook.com/docs/sharing/reference/share-dialog @@ -180,16 +184,16 @@ declare namespace facebook { // RESPONSES // //////////////////////// - interface AuthResponse { + accessToken: string; + expiresIn: number; + signedRequest: string; + userID: string; + } + + interface StatusResponse { status: string; - authResponse: { - accessToken: string; - expiresIn: number; - grantedScopes: string; - signedRequest: string; - userID: string; - }; + authResponse: AuthResponse; } interface ShareDialogResponse { diff --git a/types/koa-route/index.d.ts b/types/koa-route/index.d.ts index 33840d2842..7f2584dbfa 100644 --- a/types/koa-route/index.d.ts +++ b/types/koa-route/index.d.ts @@ -1,63 +1,66 @@ // Type definitions for koa-route 3.2 // Project: https://github.com/koajs/route#readme // Definitions by: Mike Cook +// Jaco Greeff // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 import * as Koa from 'koa'; import * as pathToRegexp from 'path-to-regexp'; -type RoutePath = string | RegExp | Array; +declare namespace KoaRoute { + type Path = string | RegExp | Array; -type RouteHandler = (this: Koa.Context, ctx: Koa.Context, ...params: any[]) => any; + type Handler = (this: Koa.Context, ctx: Koa.Context, ...params: any[]) => any; -type CreateRoute = (routeFunc: RouteHandler) => Koa.Middleware; + type CreateRoute = (routeFunc: Handler) => Koa.Middleware; -interface RouteMethod { - (path: RoutePath): CreateRoute; - (path: RoutePath, fn: RouteHandler, opts?: pathToRegexp.ParseOptions & pathToRegexp.RegExpOptions): Koa.Middleware; + interface Method { + (path: Path): CreateRoute; + (path: Path, fn: Handler, opts?: pathToRegexp.ParseOptions & pathToRegexp.RegExpOptions): Koa.Middleware; + } + + type CreateMethod = (method: string) => Method; + + interface Routes { + all: Method; + acl: Method; + bind: Method; + checkout: Method; + connect: Method; + copy: Method; + delete: Method; + del: Method; + get: Method; + head: Method; + link: Method; + lock: Method; + msearch: Method; + merge: Method; + mkactivity: Method; + mkcalendar: Method; + mkcol: Method; + move: Method; + notify: Method; + options: Method; + patch: Method; + post: Method; + propfind: Method; + proppatch: Method; + purge: Method; + put: Method; + rebind: Method; + report: Method; + search: Method; + subscribe: Method; + trace: Method; + unbind: Method; + unlink: Method; + unlock: Method; + unsubscribe: Method; + } } -type CreateRouteMethod = (method: string) => RouteMethod; - -interface KoaRoutes { - all: CreateRouteMethod; - acl: RouteMethod; - bind: RouteMethod; - checkout: RouteMethod; - connect: RouteMethod; - copy: RouteMethod; - delete: RouteMethod; - del: RouteMethod; - get: RouteMethod; - head: RouteMethod; - link: RouteMethod; - lock: RouteMethod; - msearch: RouteMethod; - merge: RouteMethod; - mkactivity: RouteMethod; - mkcalendar: RouteMethod; - mkcol: RouteMethod; - move: RouteMethod; - notify: RouteMethod; - options: RouteMethod; - patch: RouteMethod; - post: RouteMethod; - propfind: RouteMethod; - proppatch: RouteMethod; - purge: RouteMethod; - put: RouteMethod; - rebind: RouteMethod; - report: RouteMethod; - search: RouteMethod; - subscribe: RouteMethod; - trace: RouteMethod; - unbind: RouteMethod; - unlink: RouteMethod; - unlock: RouteMethod; - unsubscribe: RouteMethod; -} - -declare const routes: KoaRoutes; +declare const routes: KoaRoute.Routes; export = routes; diff --git a/types/marko/express.d.ts b/types/marko/express.d.ts new file mode 100644 index 0000000000..e9bac4091d --- /dev/null +++ b/types/marko/express.d.ts @@ -0,0 +1,20 @@ +import * as express from 'express'; +import Template from './src/runtime/html/Template'; +import { IRouterMatcher as ExpressRouterMatcher, NextFunction, PathParams } from 'express-serve-static-core'; + +declare function m(): m.Application; + +declare namespace m { + interface Response extends express.Response { + marko(template: Template, data?: any): void; + } + + interface Application extends express.Application { + get: ((name: string) => any) & ExpressRouterMatcher & MarkoRouterMatcher; + } + + type MarkoRouterMatcher = (path: PathParams, ...handlers: RequestHandler[]) => Application; + type RequestHandler = (req: express.Request, res: Response, next?: NextFunction) => any; +} + +export = m; diff --git a/types/marko/index.d.ts b/types/marko/index.d.ts new file mode 100644 index 0000000000..0c94aaa956 --- /dev/null +++ b/types/marko/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for marko 4.6 +// Project: http://markojs.com +// Definitions by: Timur Manyanov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +import { AsyncStream, Template } from './src/runtime/html'; + +export function createOut(globalData: any): AsyncStream; + +export interface TemplateOptions { + buffer?: boolean; + writeToDisk?: boolean; +} + +export function load(templatePath: string, options?: TemplateOptions): Template; +export function load(templatePath: string, templateSrc: string, options?: TemplateOptions): Template; diff --git a/types/marko/marko-tests.ts b/types/marko/marko-tests.ts new file mode 100644 index 0000000000..623ad12e5f --- /dev/null +++ b/types/marko/marko-tests.ts @@ -0,0 +1,174 @@ +import { createServer } from 'http'; +import { createWriteStream } from 'fs'; +import express = require('express'); +import asyncWriter = require('async-writer'); + +import markoExpress = require('marko/express'); +import { load } from 'marko'; +import { createWriter, AsyncStream, Template, RenderResult } from 'marko/src/runtime/html'; +import { Component } from 'marko/src/components'; +import { buildTaglibLookup, taglibFinder } from 'marko/src/compiler'; + +// tslint:disable-next-line no-var-requires +const template: Template = require('template.marko'); + +// Working with document + +(document: Document) => { + // $ExpectType RenderResult + template + .renderSync({ name: 'Marko' }) + .appendTo(document.body); + + createServer((req, res) => { + res.setHeader('content-type', 'text/html'); + // $ExpectType void + template.render({ name: 'Marko' }, res); + }).listen(8080); + + template + .render({ $global: { flags: ['mobile'] } }) + .then((result) => { + // $ExpectType RenderResult + result.appendTo(document.body); + }); + + template.render({}, (err: Error | null, result: RenderResult) => { + // $ExpectType RenderResult + result.appendTo(document.body); + }); +}; + +// WriteStream tests + +const writeStream = createWriteStream('template.html', { encoding: 'utf8' }); + +// $ExpectType void +template.render({ name: 'Frank' }, writeStream); + +// $ExpectType WriteStream +template.stream({}).pipe(writeStream); + +(req: Request) => { + // $ExpectType Readable + template.stream({ name: 'Frank' }); +}; + +// rendering tests + +const out = template.createOut(); + +// $ExpectType void +template.render({}, out); +out.on('finish', () => { + // $ExpectType string + out.getOutput(); +}); +out.end(); + +// $ExpectType void +template.render({ name: 'Frank' }, process.stdout); + +// $ExpectType string +template.renderToString({ label: 'Click me!' }); + +template.renderToString({}, (err, html) => { + // $ExpectType string + html; +}); + +// AsyncStream/AsyncWriter tests + +const writer: AsyncStream = createWriter(process.stdout); + +// $ExpectType void +template.render({ name: 'Frank' }, writer); +writer.end(); + +const asyncWriterInstance = asyncWriter.create(process.stdout); + +// $ExpectType AsyncWriter +asyncWriterInstance.write('Hello'); + +const asyncOut = asyncWriterInstance.beginAsync(); + +setTimeout(() => { + asyncOut.write('World'); + asyncOut.end(); +}, 100); + +template.render({}, asyncWriterInstance); + +// Component tests + +(component: Component) => { + // $ExpectType HTMLElement + component.getEl('header'); + + // $ExpectType HTMLElement[] + component.getEls('colors'); + + // $ExpectType Component + component.getComponent('myFancyButton'); +}; + +// markoExpress() tests + +const app = express() as markoExpress.Application; + +// $ExpectType Application +app.use(markoExpress()); + +// $ExpectType Application +app.get('/', (req: express.Request, res: markoExpress.Response) => { + // $ExpectType void + res.marko(template, { + name: 'Frank', + count: 30, + colors: ['red', 'green', 'blue'] + }); +}); + +// Taglib tests + +const lookup = buildTaglibLookup('some/dir'); + +lookup.forEachTag(tag => { + // $ExpectType string + tag.name; +}); + +lookup.forEachAttribute('div', attr => { + // $ExpectType string | undefined + attr.name; +}); + +// $ExpectType Attribute | undefined +lookup.getAttribute('foo', 'cat'); + +// $ExpectType void +taglibFinder.excludeDir('dir/Path'); + +// $ExpectType void +taglibFinder.excludePackage('packageName'); + +// load() tests + +const isomorphicTemplate = load(require.resolve('./template.marko')); +isomorphicTemplate.render({ name: 'Frank' }, process.stdout); + +const serverTemplateFromFile = load('./sample.marko', { writeToDisk: false }); +serverTemplateFromFile.render({ name: 'Frank' }, process.stdout); + +const serverTemplateFromString = load('sample.marko', '
Hello $!{data.name}
'); +serverTemplateFromString.render({ name: 'Frank' }, process.stdout); + +// node-require tests + +import { install, getExtensions } from 'marko/node-require'; + +// $ExpectType void +install(); + +// $ExpectType any +getExtensions(); diff --git a/types/marko/node-require.d.ts b/types/marko/node-require.d.ts new file mode 100644 index 0000000000..eccf99e526 --- /dev/null +++ b/types/marko/node-require.d.ts @@ -0,0 +1,3 @@ +export function install(options?: any): void; + +export function getExtensions(): any; diff --git a/types/marko/src/compiler/config.d.ts b/types/marko/src/compiler/config.d.ts new file mode 100644 index 0000000000..c4d006280f --- /dev/null +++ b/types/marko/src/compiler/config.d.ts @@ -0,0 +1,11 @@ +export default interface Config { + checkUpToDate?: boolean; + writeToDisk?: boolean; + assumeUpToDate?: boolean; + preserveWhitespace?: boolean; + output?: 'vdom' | 'html'; + writeVersionComment?: boolean; + ignoreUnrecognizedTags?: boolean; + escapeAtTags?: boolean; + autoKeyEnabled?: boolean; +} diff --git a/types/marko/src/compiler/index.d.ts b/types/marko/src/compiler/index.d.ts new file mode 100644 index 0000000000..cdc73b0c7c --- /dev/null +++ b/types/marko/src/compiler/index.d.ts @@ -0,0 +1,45 @@ +import Config from './config'; +import * as taglibLookup from './taglib-lookup'; +import * as taglibLoader from './taglib-loader'; +import * as taglibFinder from './taglib-finder'; +import * as modules from './modules'; + +export const isVDOMSupported: true; +export const builder: any; +export const defaultOptions: Config; +export const config: Config; + +export function createBuilder(options: any): any; + +export function compileFile(filename: string, optionsOrCallback?: any, callback?: any): any; + +export function compile(src: any, filename: string, optionsOrCallback: any, callback?: any): any; + +export function compileForBrowser(src: any, filename: string, optionsOrCallback: any, callback?: any): any; + +export function compileFileForBrowser(filename: string, optionsOrCallback?: any, callback?: any): any; + +export function parseRaw(templateSrc: any, filename: string): any; + +export function createInlineCompiler(filename: string, userOptions?: any): any; + +export function checkUpToDate(templateFile: any, templateJsFile: any): boolean; + +export function getLastModified(path: string, optionsOrCallback: any, callback: any): void; + +export function createWalker(options: any): any; + +export function configure(newConfig?: Config): void; + +export function clearCaches(): void; + +export function buildTaglibLookup(dirname: string): taglibLookup.TaglibLookup; + +export function registerTaglib(filePath: string): void; + +export { + taglibLookup, + taglibLoader, + taglibFinder, + modules +}; diff --git a/types/marko/src/compiler/modules.d.ts b/types/marko/src/compiler/modules.d.ts new file mode 100644 index 0000000000..4b128b2230 --- /dev/null +++ b/types/marko/src/compiler/modules.d.ts @@ -0,0 +1,7 @@ +export function require(path: string): any; + +export function resolve(path: string): string; + +export function resolveFrom(from: string, target: string): string | null; + +export function deresolve(targetFilename: string, from: string): string; diff --git a/types/marko/src/compiler/taglib-finder/index.d.ts b/types/marko/src/compiler/taglib-finder/index.d.ts new file mode 100644 index 0000000000..2f16371ab8 --- /dev/null +++ b/types/marko/src/compiler/taglib-finder/index.d.ts @@ -0,0 +1,11 @@ +import Taglib from '../taglib-loader/Taglib'; + +export function find(dirname: string, registeredTaglibs: Taglib[]): Taglib[]; + +export function excludeDir(dir: string): void; + +export function excludePackage(name: string): void; + +export function reset(): void; + +export function clearCache(): void; diff --git a/types/marko/src/compiler/taglib-loader/Attribute.d.ts b/types/marko/src/compiler/taglib-loader/Attribute.d.ts new file mode 100644 index 0000000000..5eea79f6ce --- /dev/null +++ b/types/marko/src/compiler/taglib-loader/Attribute.d.ts @@ -0,0 +1,22 @@ +export default class Attribute { + type: string | null; + key: string; + filePath: string; + ref?: string; + name?: string; + preserveName?: string; + targetProperty: string | null; + defaultValue: string; + pattern?: any; + setFlag: string | null; + setContextFlag: string; + required: boolean; + ignore: boolean; + dynamicAttribute: boolean; + allowExpressions: boolean; + removeDashes: boolean; + autocomplete: boolean; + html: boolean; + deprecated: any; + enum: any; +} diff --git a/types/marko/src/compiler/taglib-loader/Tag.d.ts b/types/marko/src/compiler/taglib-loader/Tag.d.ts new file mode 100644 index 0000000000..7172ad3f89 --- /dev/null +++ b/types/marko/src/compiler/taglib-loader/Tag.d.ts @@ -0,0 +1,69 @@ +import Taglib from './Taglib'; +import Attribute from './Attribute'; +import Transformer from './Transformer'; + +declare class Tag { + name: string; + dir: string; + taglibId: string | null; + taglibPath: string | null; + attributes: { [name: string]: Attribute }; + attributeGroups: string[]; + transformers: { [path: string]: Transformer }; + patternAttributes: Attribute[]; + renderer: any; + template: any; + codeGeneratorModulePath: string | null; + nodeFactoryPath: string | null; + nestedVariables: any; + importedVariables: any; + bodyFunction: any; + nestedTags: { [name: string]: Tag } | null; + isNestedTag: boolean; + isRepeated: boolean | null; + parentTagName: string | null; + openTagOnly: any; + body: any; + type: any; + targetProperty?: string; + + constructor(filePath?: string); + + addAttribute(attr: Attribute): void; + + addImportedVariable(importedVariable: any): void; + + addNestedTag(nestedTag: Tag): void; + + addNestedVariable(nestedVariable: any): void; + + addTransformer(transformer: Transformer): void; + + forEachAttribute(callback: (attr: Attribute) => void, thisObj?: any): void; + + forEachImportedVariable(callback: (importedVariable: any) => void, thisObj?: any): void; + + forEachNestedTag(callback: (nestedTag: Tag) => void, thisObj?: any): void; + + forEachTransformer(callback: (transformer: Transformer) => void, thisObj?: any): void; + + forEachVariable(callback: (nestedVariable: any) => void, thisObj?: any): void; + + getAttribute(attrName: string): Attribute | undefined; + + getNodeFactory(): any; + + hasAttribute(attrName: string): boolean; + + hasNestedTags(): boolean; + + hasTransformers(): boolean; + + setBodyFunction(name: string, params: any): void; + + setBodyProperty(propertyName: string): void; + + setTaglib(taglib: Taglib): void; +} + +export = Tag; diff --git a/types/marko/src/compiler/taglib-loader/Taglib.d.ts b/types/marko/src/compiler/taglib-loader/Taglib.d.ts new file mode 100644 index 0000000000..15492613c3 --- /dev/null +++ b/types/marko/src/compiler/taglib-loader/Taglib.d.ts @@ -0,0 +1,38 @@ +import Attribute from './Attribute'; +import Transformer from './Transformer'; +import Tag = require('./Tag'); + +export default class Taglib { + id: string; + /** @deprecated */ + path: string; + filePath: string; + dirname: string; + tags: { [name: string]: Tag }; + attributes: { [key: string]: Attribute }; + attributeGroups: { [name: string]: Attribute }; + patternAttributes: Attribute[]; + textTransformers: Transformer[]; + transformers: Transformer[]; + inputFilesLookup: any; + imports: any; + importsLookup: any; + + constructor(filePath: string); + + addAttribute(attribute: Attribute): void; + + getAttribute(name: string): Attribute | undefined; + + addTag(tag: Tag): void; + + addTransformer(transformer: Transformer): void; + + addTextTransformer(transformer: Transformer): void; + + addImport(path: string): void; + + forEachTag(callback: (tag: Tag) => void, thisObj?: any): void; + + toJSON(): any; +} diff --git a/types/marko/src/compiler/taglib-loader/Transformer.d.ts b/types/marko/src/compiler/taglib-loader/Transformer.d.ts new file mode 100644 index 0000000000..5c47692074 --- /dev/null +++ b/types/marko/src/compiler/taglib-loader/Transformer.d.ts @@ -0,0 +1,14 @@ +import Tag = require('./Tag'); + +export default class Transformer { + id: number; + name: string | null; + tag: Tag | null; + path: string | null; + priority: any; + properties: any; + taglibId: string; + + constructor(); + getFunc(): any; +} diff --git a/types/marko/src/compiler/taglib-loader/index.d.ts b/types/marko/src/compiler/taglib-loader/index.d.ts new file mode 100644 index 0000000000..6382ad6cd3 --- /dev/null +++ b/types/marko/src/compiler/taglib-loader/index.d.ts @@ -0,0 +1,14 @@ +import _Taglib from './Taglib'; +import Tag = require('./Tag'); + +export class Taglib extends _Taglib {} + +export function createTaglib(filePath: string): Taglib; + +export function loadTaglibFromProps(taglib: Taglib, taglibProps: any): Taglib; + +export function loadTaglibFromFile(filePath: string): Taglib; + +export function loadTag(tagProps: any, filePath: string): Tag; + +export function clearCache(): void; diff --git a/types/marko/src/compiler/taglib-lookup/TaglibLookup.d.ts b/types/marko/src/compiler/taglib-lookup/TaglibLookup.d.ts new file mode 100644 index 0000000000..c90535d2d1 --- /dev/null +++ b/types/marko/src/compiler/taglib-lookup/TaglibLookup.d.ts @@ -0,0 +1,41 @@ +import Taglib from '../taglib-loader/Taglib'; +import Tag = require('../taglib-loader/Tag'); +import Attribute from '../taglib-loader/Attribute'; +import Transformer from '../taglib-loader/Transformer'; + +export interface Element { + tagName: string; +} + +export default class TaglibLookup { + merged: { + attributeGroups: any; + }; + taglibsById: { [id: string]: Taglib }; + + constructor(); + + hasTaglib(taglib: Taglib): boolean; + + addTaglib(taglib: Taglib): void; + + getTagsSorted(): Tag[]; + + forEachTag(callback: (tag: Tag) => void | boolean): void; + + forEachAttribute(tagName: string, callback: (attrDef: Attribute, tag: Tag) => void): void; + + getTag(element: string | Element): Tag | undefined; + + getAttribute(element: string | Element, attr: string | { name: string }): Attribute | undefined; + + forEachTemplateTransformer(callback: (trans: Transformer) => any, thisObj?: any): void; + + forEachNodeTransformer(node: any, callback: (trans: Transformer) => any, thisObj?: any): void; + + forEachTagTransformer(element: string | Element, callback: (trans: Transformer) => any, thisObj?: any): void; + + forEachTextTransformer(callback: (trans: Transformer) => any, thisObj?: any): void; + + getInputFiles(): string[]; +} diff --git a/types/marko/src/compiler/taglib-lookup/index.d.ts b/types/marko/src/compiler/taglib-lookup/index.d.ts new file mode 100644 index 0000000000..fa4cb321ef --- /dev/null +++ b/types/marko/src/compiler/taglib-lookup/index.d.ts @@ -0,0 +1,12 @@ +import Taglib from '../taglib-loader/Taglib'; +import _TaglibLookup from './TaglibLookup'; + +export class TaglibLookup extends _TaglibLookup {} + +export const registeredTaglibs: Taglib[]; + +export function registerTaglib(taglib: Taglib): void; + +export function buildLookup(dirname: string): TaglibLookup; + +export function clearCache(): void; diff --git a/types/marko/src/components/Component.d.ts b/types/marko/src/components/Component.d.ts new file mode 100644 index 0000000000..91cdb40bfe --- /dev/null +++ b/types/marko/src/components/Component.d.ts @@ -0,0 +1,28 @@ +import { EventEmitter } from 'events'; +import DomElement from '../runtime/DomElement'; + +export default interface Component extends EventEmitter, DomElement { + /** @deprecated */ + el: HTMLElement; + /** @deprecated */ + els: HTMLElement[]; + id: string; + input: any; + state: any; + destroy(): void; + elId(key: string, index?: number): string; + forceUpdate(): void; + getComponent(key: string, index?: number): Component; + getComponents(key: string): Component[]; + getEl(key?: string, index?: number): HTMLElement; + getElId(key: string, index?: number): string; + getEls(key?: string): HTMLElement[]; + isDestroyed(): boolean; + replaceState(newState: any): void; + setState(name: string, value: any): void; + setState(name: any): void; + setStateDirty(name: string, value?: any): void; + shouldUpdate(newState: any, newProps: any): boolean; + update(): void; + (id: string): this; +} diff --git a/types/marko/src/components/index.d.ts b/types/marko/src/components/index.d.ts new file mode 100644 index 0000000000..cda052eefc --- /dev/null +++ b/types/marko/src/components/index.d.ts @@ -0,0 +1,8 @@ +import _Component from './Component'; + +export function writeInitComponentsCode(fromOut: any, targetOut: any, shouldIncludeAll: any): void; + +export function getRenderedComponents(out: any): any; + +// tslint:disable-next-line no-empty-interface +export interface Component extends _Component {} diff --git a/types/marko/src/components/taglib/TransformHelper/getComponentFiles.d.ts b/types/marko/src/components/taglib/TransformHelper/getComponentFiles.d.ts new file mode 100644 index 0000000000..70456b82c3 --- /dev/null +++ b/types/marko/src/components/taglib/TransformHelper/getComponentFiles.d.ts @@ -0,0 +1,12 @@ +declare function getComponentFiles(filename: string): getComponentFiles.ComponentFiles | null; + +declare namespace getComponentFiles { + interface ComponentFiles { + styles: string[]; + file: string | null; + browserFile: string | null; + package: string | null; + } +} + +export = getComponentFiles; diff --git a/types/marko/src/runtime/Async.d.ts b/types/marko/src/runtime/Async.d.ts new file mode 100644 index 0000000000..41b03e30d6 --- /dev/null +++ b/types/marko/src/runtime/Async.d.ts @@ -0,0 +1,15 @@ +import { EventEmitter } from 'events'; + +export default interface Async extends EventEmitter, Promise { + sync(): void; + isSync(): boolean; + write(str?: string): this; + w(str?: string): this; + beginAsync(options?: any): this; + error(e: Error): this; + flush(): void; + createOut(): this; + endElement(): void; + onLast(callback: any): this; + c(componentDef: any, key: any, customEvents: any): void; +} diff --git a/types/marko/src/runtime/DomElement.d.ts b/types/marko/src/runtime/DomElement.d.ts new file mode 100644 index 0000000000..2615151ff8 --- /dev/null +++ b/types/marko/src/runtime/DomElement.d.ts @@ -0,0 +1,8 @@ +export default interface DomElement { + appendTo(referenceEl: string | Node): this; + prependTo(referenceEl: string | Node): this; + replace(referenceEl: string | Node): this; + replaceChildrenOf(referenceEl: string | Node): this; + insertBefore(referenceEl: string | Node): this; + insertAfter(referenceEl: string | Node): this; +} diff --git a/types/marko/src/runtime/html/AsyncStream.d.ts b/types/marko/src/runtime/html/AsyncStream.d.ts new file mode 100644 index 0000000000..2523a5015b --- /dev/null +++ b/types/marko/src/runtime/html/AsyncStream.d.ts @@ -0,0 +1,15 @@ +import Async from '../Async'; + +export default interface AsyncStream extends Async { + DEFAULT_TIMEOUT: number; + INCLUDE_STACK: boolean; + + (global: any, writer?: any, parentOut?: any, shouldBuffer?: boolean): this; + enableAsyncStackTrace(): void; + text(str: any): void; + element(tagName: string, elementAttrs: any, openTagOnly: boolean): void; + beginElement(name: string, elementAttrs: any): void; + end(data?: any): this; + /** @deprecated */ + getOutput(): string; +} diff --git a/types/marko/src/runtime/html/RenderResult.d.ts b/types/marko/src/runtime/html/RenderResult.d.ts new file mode 100644 index 0000000000..c2d3f06d47 --- /dev/null +++ b/types/marko/src/runtime/html/RenderResult.d.ts @@ -0,0 +1,13 @@ +import DomElement from '../DomElement'; +import Component from '../../components/Component'; + +export default interface RenderResult extends DomElement { + document: Document | false; + + (out: any): this; + getComponent(): Component; + getComponents(selector?: any): Component[]; + afterInsert(doc: Document): this; + getNode(doc: Document): Node; + getOutput(): any; +} diff --git a/types/marko/src/runtime/html/Template.d.ts b/types/marko/src/runtime/html/Template.d.ts new file mode 100644 index 0000000000..587ad81ab3 --- /dev/null +++ b/types/marko/src/runtime/html/Template.d.ts @@ -0,0 +1,47 @@ +/// + +import * as stream from 'stream'; +import { ServerResponse } from 'http'; +import AsyncStream from './AsyncStream'; +import RenderResult from './RenderResult'; +import AsyncVDOMBuilder from '../vdom/AsyncVDOMBuilder'; +import { AsyncWriter } from 'async-writer'; + +export class Readable extends stream.Readable { + _t: any; + _d: any; + _shouldBuffer: boolean; + _rendered: boolean; + + constructor(template: Template, data: any, options: any); + + write(data: any): void; +} + +export interface Renderable { + createOut: any; + + renderToString(data?: any): string; + + renderToString(data: any, callback: (err: Error | null, result: string) => void): undefined; + + renderSync(data?: any): RenderResult; + + render(data?: any): Promise; + + render(data: any, out: AsyncStream | AsyncWriter | AsyncVDOMBuilder | stream.Writable | + ((err: any, result: RenderResult) => void)): void; +} + +export default interface Template extends Renderable { + path: string; + _: any; + ___shouldBuffer: boolean; + meta: any; + + (path: string, renderFunc: any, options: any): Template; + + createOut(globalData?: any, writer?: any, parentOut?: any, buffer?: any): AsyncStream; + + stream(data: any): Readable; +} diff --git a/types/marko/src/runtime/html/index.d.ts b/types/marko/src/runtime/html/index.d.ts new file mode 100644 index 0000000000..25cd87e4bc --- /dev/null +++ b/types/marko/src/runtime/html/index.d.ts @@ -0,0 +1,16 @@ +import MarkoAsyncStream from './AsyncStream'; +import MarkoTemplate from './Template'; +import MarkoRenderResult from './RenderResult'; + +export function createWriter(writer: any): AsyncStream; + +export function enableAsyncStackTrace(): void; + +// tslint:disable-next-line no-empty-interface +export interface Template extends MarkoTemplate {} + +// tslint:disable-next-line no-empty-interface +export interface AsyncStream extends MarkoAsyncStream {} + +// tslint:disable-next-line no-empty-interface +export interface RenderResult extends MarkoRenderResult {} diff --git a/types/marko/src/runtime/vdom/AsyncVDOMBuilder.d.ts b/types/marko/src/runtime/vdom/AsyncVDOMBuilder.d.ts new file mode 100644 index 0000000000..98e876576f --- /dev/null +++ b/types/marko/src/runtime/vdom/AsyncVDOMBuilder.d.ts @@ -0,0 +1,25 @@ +import Component from '../../components/Component'; +import Async from '../Async'; + +export default interface AsyncVDOMBuilder extends Async { + isVDOM: true; + data: any; + global: any; + + (globalData?: any, parentNode?: any, parentOut?: any): this; + bc(component: Component): any; + n(node: any, component: Component): this; + node(node: any): this; + h(html?: string): this; + html(html?: string): this; + ed(tagName: string, attrs: any, key: string, component: Component, childCount: number, flags?: number, props?: any): any; + bed(tagName: string, attrs: any, key: string, component: Component, childCount: number, flags?: number, props?: any): this; + ee(): void; + comment(comment: any): this; + t(text: any): this | string | void; + text(text: any): this | string | void; + element(tagName: string, attrs: any, key: string, component: Component, childCount: number, flags?: number, props?: any): any; + be(tagName: string, attrs: any, key: string, component: Component, childCount: number, flags?: number, props?: any): this; + beginElement(tagName: string, attrs: any, key: string, component: Component, childCount: number, flags?: number, props?: any): this; + end(): this; +} diff --git a/types/marko/tsconfig.json b/types/marko/tsconfig.json new file mode 100644 index 0000000000..2d9f2eb4f9 --- /dev/null +++ b/types/marko/tsconfig.json @@ -0,0 +1,45 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "express.d.ts", + "node-require.d.ts", + "marko-tests.ts", + "src/compiler/index.d.ts", + "src/compiler/config.d.ts", + "src/compiler/modules.d.ts", + "src/compiler/taglib-finder/index.d.ts", + "src/compiler/taglib-loader/index.d.ts", + "src/compiler/taglib-loader/Attribute.d.ts", + "src/compiler/taglib-loader/Tag.d.ts", + "src/compiler/taglib-loader/Taglib.d.ts", + "src/compiler/taglib-loader/Transformer.d.ts", + "src/compiler/taglib-lookup/index.d.ts", + "src/compiler/taglib-lookup/TaglibLookup.d.ts", + "src/components/index.d.ts", + "src/components/Component.d.ts", + "src/components/taglib/TransformHelper/getComponentFiles.d.ts", + "src/runtime/Async.d.ts", + "src/runtime/DomElement.d.ts", + "src/runtime/html/index.d.ts", + "src/runtime/html/Template.d.ts", + "src/runtime/html/RenderResult.d.ts", + "src/runtime/html/AsyncStream.d.ts", + "src/runtime/vdom/AsyncVDOMBuilder.d.ts" + ] +} diff --git a/types/marko/tslint.json b/types/marko/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/marko/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 95395bc2b8..27ffa974fd 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -16,6 +16,9 @@ import * as url from "url"; import { Response as NodeResponse } from "node-fetch"; declare namespace next { + /** Map object used in query strings. */ + type QueryStringMapObject = Record; + /** * Context object used in methods like `getInitialProps()` * <> @@ -24,15 +27,7 @@ declare namespace next { /** path section of URL */ pathname: string; /** query string section of URL parsed as an object */ - query: { - [key: string]: - | boolean - | boolean[] - | number - | number[] - | string - | string[]; - }; + query: QueryStringMapObject; /** String of the actual path (including the query) shows in the browser */ asPath: string; /** HTTP request object (server only) */ @@ -43,6 +38,8 @@ declare namespace next { jsonPageRes?: NodeResponse; /** Error object if any error is encountered during the rendering */ err?: Error; + /** Whether we're running on the server environment or not. */ + isServer?: boolean; } type NextSFC = NextStatelessComponent; @@ -101,15 +98,7 @@ declare namespace next { req: http.IncomingMessage, res: http.ServerResponse, pathname: string, - query?: { - [key: string]: - | boolean - | boolean[] - | number - | number[] - | string - | string[]; - }, + query?: QueryStringMapObject, parsedUrl?: UrlLike ): Promise; renderError( @@ -117,15 +106,7 @@ declare namespace next { req: http.IncomingMessage, res: http.ServerResponse, pathname: string, - query?: { - [key: string]: - | boolean - | boolean[] - | number - | number[] - | string - | string[]; - } + query?: QueryStringMapObject ): Promise; render404( req: http.IncomingMessage, @@ -136,30 +117,14 @@ declare namespace next { req: http.IncomingMessage, res: http.ServerResponse, pathname: string, - query?: { - [key: string]: - | boolean - | boolean[] - | number - | number[] - | string - | string[]; - } + query?: QueryStringMapObject ): Promise; renderErrorToHTML( err: any, req: http.IncomingMessage, res: http.ServerResponse, pathname: string, - query?: { - [key: string]: - | boolean - | boolean[] - | number - | number[] - | string - | string[]; - } + query?: QueryStringMapObject ): Promise; serveStatic( diff --git a/types/office-js/index.d.ts b/types/office-js/index.d.ts index cb15dd864a..d5d694225e 100644 --- a/types/office-js/index.d.ts +++ b/types/office-js/index.d.ts @@ -685,7 +685,7 @@ declare namespace Office { * * @param startAddress - Accepts the initial HTTPS URL that opens in the dialog. * @param options - Optional. Accepts an {@link Office.DialogOptions} object to define dialog display. - * @param callback - Optional. Accepts a callback method to handle the dialog creation attempt. If successful, the AsyncResult.value is a DialogHandler object. + * @param callback - Optional. Accepts a callback method to handle the dialog creation attempt. If successful, the AsyncResult.value is a Dialog object. */ displayDialogAsync(startAddress: string, options?: DialogOptions, callback?: (result: AsyncResult) => void): void; /** @@ -1132,6 +1132,10 @@ declare namespace Office { * - DialogEventReceived. Triggered when the dialog box has been closed or otherwise unloaded. */ addEventHandler(eventType: Office.EventType, handler: Function): void; + /** + * FOR INTERNAL USE ONLY. DO NOT CALL IN YOUR CODE. + */ + sendMessage(name: string): void; } } diff --git a/types/polyfill-service/index.d.ts b/types/polyfill-service/index.d.ts new file mode 100644 index 0000000000..da4418f8cf --- /dev/null +++ b/types/polyfill-service/index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for polyfill-service 3.25 +// Project: https://github.com/financial-times/polyfill-service#readme +// Definitions by: Arturas Molcanovas +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +export type PolyfillFlag = 'gated' | 'always'; +export type Unknown = 'polyfill' | 'ignore'; + +export interface Feature { + flags?: PolyfillFlag[]; +} + +export interface Features { + [feature: string]: Feature; +} + +export interface GetPolyfillsOptions { + uaString: string; + features?: Features; + excludes?: string[]; +} + +export interface GetPolyfillStringOptions extends GetPolyfillsOptions { + minify?: boolean; + unknown?: Unknown; +} + +export interface PolyfillSpec { + aliasOf?: Set; + flags: Set; +} + +export interface GetPolyfillsResponse { + [name: string]: PolyfillSpec; +} + +export function listAllPolyfills(): Promise>; + +export function getPolyfillString(options: GetPolyfillStringOptions): Promise; + +export function getPolyfills(options: GetPolyfillsOptions): Promise; diff --git a/types/polyfill-service/polyfill-service-tests.ts b/types/polyfill-service/polyfill-service-tests.ts new file mode 100644 index 0000000000..b74bfbd7f7 --- /dev/null +++ b/types/polyfill-service/polyfill-service-tests.ts @@ -0,0 +1,43 @@ +import * as svc from 'polyfill-service'; + +const o: svc.GetPolyfillsOptions = { + uaString: '' +}; + +o.excludes = ['foo']; +o.features = { + foo: {}, + bar: {flags: ['gated', 'always']} +}; + +const o2: svc.GetPolyfillStringOptions = { + uaString: '' +}; + +o2.excludes = ['foo']; +o2.features = { + foo: {}, + bar: {flags: ['gated', 'always']} +}; +o2.minify = true; +o2.minify = false; +o2.unknown = 'polyfill'; +o2.unknown = 'ignore'; + +svc.listAllPolyfills().then(v => { + v[0].toLocaleLowerCase(); +}); + +svc.getPolyfillString(o2).then(s => { + s.toLocaleUpperCase(); +}); + +svc.getPolyfills(o).then(r => { + const p = r.Symbol; + p.flags.clear(); + + const a = p.aliasOf; + if (a) { + a.clear(); + } +}); diff --git a/types/polyfill-service/tsconfig.json b/types/polyfill-service/tsconfig.json new file mode 100644 index 0000000000..c2c1abf8c0 --- /dev/null +++ b/types/polyfill-service/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "polyfill-service-tests.ts" + ] +} diff --git a/types/polyfill-service/tslint.json b/types/polyfill-service/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/polyfill-service/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/twig/index.d.ts b/types/twig/index.d.ts index 742958535d..29f0e0be56 100644 --- a/types/twig/index.d.ts +++ b/types/twig/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for twig 1.10 +// Type definitions for twig 1.12 // Project: https://github.com/twigjs/twig.js // Definitions by: Carlos Ballesteros Velasco // Tim Schumacher @@ -12,11 +12,12 @@ export interface Parameters { macros?: any; base?: any; path?: any; - url?: any; + href?: any; name?: any; method?: any; options?: any; data?: any; + async?: any; } export interface Template { diff --git a/types/twig/twig-tests.ts b/types/twig/twig-tests.ts index 3f787cf77c..39fbdc804d 100644 --- a/types/twig/twig-tests.ts +++ b/types/twig/twig-tests.ts @@ -14,7 +14,8 @@ const params: twig.Parameters = { method: value, name: value, options: value, - url: value + href: value, + async: value }; const temp: twig.Template = twig.twig(params); diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index 292af9e31d..597c86fa52 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -1594,6 +1594,14 @@ declare namespace webpack { */ exec(code: string, filename: string): any; + /** + * Resolves the given request to a module, applies all configured loaders and calls + * back with the generated source, the sourceMap and the module instance (usually an + * instance of NormalModule). Use this function if you need to know the source code + * of another module to generate the result. + */ + loadModule(request: string, callback: (err: Error | null, source: string, sourceMap: RawSourceMap, module: Module) => void): any; + /** * Resolve a request like a require expression. */ diff --git a/types/webpack/webpack-tests.ts b/types/webpack/webpack-tests.ts index 913eea0b19..5a41905b8d 100644 --- a/types/webpack/webpack-tests.ts +++ b/types/webpack/webpack-tests.ts @@ -516,6 +516,7 @@ function loader(this: webpack.loader.LoaderContext, source: string | Buffer, sou this.addDependency(''); + this.loadModule('path', (err: Error | null, result: string, sourceMap: RawSourceMap, module: webpack.Module) => { }); this.resolve('context', 'request', (err: Error, result: string) => { }); this.emitWarning('warning message'); diff --git a/types/wepy-redux/index.d.ts b/types/wepy-redux/index.d.ts index 8e16e57b27..be516d18eb 100644 --- a/types/wepy-redux/index.d.ts +++ b/types/wepy-redux/index.d.ts @@ -2,9 +2,10 @@ // Project: https://github.com/Tencent/wepy/tree/1.7.x/packages/wepy-redux // Definitions by: Jiayu Liu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 +// TypeScript Version: 2.3 import wepy from "wepy"; +import { Store } from "redux"; export interface MapStateToProps { [propName: string]: ((state: any) => any) | string; @@ -18,4 +19,6 @@ export function connect( mapDispatchToProps: MapDispatchToProps ): ((original: T) => T); -export function setStore(store: any): void; +export function setStore(store: Store): void; + +export function getStore(): Store; diff --git a/types/wepy-redux/package.json b/types/wepy-redux/package.json new file mode 100644 index 0000000000..7f5b19d45b --- /dev/null +++ b/types/wepy-redux/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "redux": "^4.0.0" + } +} diff --git a/types/wepy-redux/wepy-redux-tests.ts b/types/wepy-redux/wepy-redux-tests.ts index 65274613ab..8444c7cc2e 100644 --- a/types/wepy-redux/wepy-redux-tests.ts +++ b/types/wepy-redux/wepy-redux-tests.ts @@ -1,5 +1,17 @@ import wepy from "wepy"; -import { connect } from "wepy-redux"; +import { createStore } from "redux"; +import { connect, getStore, setStore } from "wepy-redux"; + +const store = createStore( + (counter: number | undefined, action: { type: string; payload: number }) => + counter || 0 + action.payload, + 0 +); + +setStore(store); + +const s = getStore(); +s.dispatch({ type: "a" }); interface State { counter: {