From da59c6f5542c09dd808cf6f29ee044aefd9a7487 Mon Sep 17 00:00:00 2001 From: Ivaylo Bratoev Date: Wed, 27 Sep 2017 19:21:16 +0300 Subject: [PATCH 001/127] Cleanup redundant type parameters --- types/react-native/index.d.ts | 8 ++++---- types/react-native/test/index.tsx | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 69f012d038..b71afc7463 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -5322,8 +5322,8 @@ export interface SystraceStatic { export interface DataSourceAssetCallback { rowHasChanged?: (r1: any, r2: any) => boolean sectionHeaderHasChanged?: (h1: any, h2: any) => boolean - getRowData?: (dataBlob: any, sectionID: number | string, rowID: number | string) => T - getSectionHeaderData?: (dataBlob: any, sectionID: number | string) => T + getRowData?: (dataBlob: any, sectionID: number | string, rowID: number | string) => any + getSectionHeaderData?: (dataBlob: any, sectionID: number | string) => any } /** @@ -5383,7 +5383,7 @@ export interface ListViewDataSource { * handle merging of old and new data separately and then pass that into * this function as the `dataBlob`. */ - cloneWithRows(dataBlob: Array | { [key: string]: any }, rowIdentities?: Array): ListViewDataSource + cloneWithRows(dataBlob: Array | { [key: string]: any }, rowIdentities?: Array): ListViewDataSource /** * This performs the same function as the `cloneWithRows` function but here @@ -5631,7 +5631,7 @@ interface PlatformStatic { interface DeviceEventEmitterStatic extends EventEmitter { sharedSubscriber: EventSubscriptionVendor new(): DeviceEventEmitterStatic; - addListener( type: string, listener: ( data: T ) => void, context?: any ): EmitterSubscription; + addListener( type: string, listener: ( data: any ) => void, context?: any ): EmitterSubscription; } // Used by Dimensions below diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 9771db9bc9..15f86af6c3 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -18,6 +18,8 @@ import { AppStateIOS, BackAndroid, Button, + DataSourceAssetCallback, + DeviceEventEmitterStatic, Dimensions, InteractionManager, ListView, @@ -369,3 +371,18 @@ class MaskedViewTest extends React.Component { ) } } + +// DataSourceAssetCallback +const dataSourceAssetCallback1: DataSourceAssetCallback = { + rowHasChanged: (r1, r2) => true, + sectionHeaderHasChanged: (h1, h2) => true, + getRowData: (dataBlob, sectionID, rowID) => (sectionID as number) + (rowID as number), + getSectionHeaderData: (dataBlob, sectionID) => sectionID as string, +} + +const dataSourceAssetCallback2: DataSourceAssetCallback = {} + +// DeviceEventEmitterStatic +const deviceEventEmitterStatic: DeviceEventEmitterStatic = null; +deviceEventEmitterStatic.addListener('keyboardWillShow', (data) => true); +deviceEventEmitterStatic.addListener('keyboardWillShow', (data) => true, {}); From e2ac4b9aa4cde129c8f4262f4fdce8ea6cc16cac Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 27 Sep 2017 13:26:14 -0700 Subject: [PATCH 002/127] mongoose-simple-random: Convert to external module (#20083) --- types/mongoose-simple-random/index.d.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/types/mongoose-simple-random/index.d.ts b/types/mongoose-simple-random/index.d.ts index 679ba1fbee..fb8edd3500 100644 --- a/types/mongoose-simple-random/index.d.ts +++ b/types/mongoose-simple-random/index.d.ts @@ -1,17 +1,12 @@ // Type definitions for mongoose-simple-random 0.4 // Project: https://github.com/larryprice/mongoose-simple-random -// Definitions by: My Self +// Definitions by: Roberts Slisans // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module 'mongoose-simple-random' { - import mongoose = require('mongoose'); - // Dummy function allows to avoid hard to kill or fix tslint warning - // (exporting pluginFunc will make this a non-importable module) - function pluginFunc(schema: mongoose.Schema): void; - // Let allows typescript to still use ES2015 style imports - let plugin: typeof pluginFunc; - export = plugin; -} +import mongoose = require('mongoose'); +declare function pluginFunc(schema: mongoose.Schema): void; +declare namespace pluginFunc {} +export = pluginFunc; declare module "mongoose" { interface Model extends NodeJS.EventEmitter, ModelProperties { From 036c225f85e87c0c64628c38207343a47b7abf52 Mon Sep 17 00:00:00 2001 From: Martin Chaov Date: Wed, 27 Sep 2017 23:42:11 +0300 Subject: [PATCH 003/127] Updated Enzyme typings (#20073) --- types/enzyme/index.d.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/types/enzyme/index.d.ts b/types/enzyme/index.d.ts index b0d044a484..c2f99f3d19 100644 --- a/types/enzyme/index.d.ts +++ b/types/enzyme/index.d.ts @@ -23,7 +23,7 @@ export class ElementClass extends Component { * all specified in the implementation. TS chooses the EnzymePropSelector overload and loses the generics */ export interface ComponentClass { - new (props?: Props, context?: any): Component; + new(props?: Props, context?: any): Component; } export type StatelessComponent = (props: Props, context?: any) => JSX.Element; @@ -612,3 +612,10 @@ export function mount(node: ReactElement

, options?: MountRendererProps) * @param [options] */ export function render(node: ReactElement

, options?: any): Cheerio; + +/** + * Configure enzyme to use the correct adapter for the react verstion + * This is enabling the Enzyme configuration with adapters in TS + * @param options + */ +export function configure(options: { adapter: any }): void; From a073151885738c6e61c8296215c5152ae9bc9cd4 Mon Sep 17 00:00:00 2001 From: Christian Rackerseder Date: Wed, 27 Sep 2017 22:45:40 +0200 Subject: [PATCH 004/127] [loglevel] Moved everything to a namespace called log (#20063) --- types/loglevel/index.d.ts | 306 +++++++++++----------- types/loglevel/test/loglevel-tests.ts | 2 +- types/loglevel/test/loglevel-umd-tests.ts | 2 +- 3 files changed, 156 insertions(+), 154 deletions(-) diff --git a/types/loglevel/index.d.ts b/types/loglevel/index.d.ts index 74bfdfb3d3..c32bdf52a0 100644 --- a/types/loglevel/index.d.ts +++ b/types/loglevel/index.d.ts @@ -7,164 +7,166 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 -declare var log: Logger; +declare var log: log.Logger; export as namespace log; export = log; -/** - * Log levels - */ -interface LogLevel { - TRACE: 0; - DEBUG: 1; - INFO: 2; - WARN: 3; - ERROR: 4; - SILENT: 5; -} - -/** - * Possible log level numbers. - */ -type LogLevelNumbers = LogLevel[keyof LogLevel]; - -type LoggingMethod = (...message: any[]) => void; - -type MethodFactory = (methodName: string, level: LogLevelNumbers, loggerName: string) => LoggingMethod; - -interface Logger { +declare namespace log { /** - * Available log levels. + * Log levels */ - readonly levels: LogLevel; + interface LogLevel { + TRACE: 0; + DEBUG: 1; + INFO: 2; + WARN: 3; + ERROR: 4; + SILENT: 5; + } /** - * Plugin API entry point. This will be called for each enabled method each time the level is set - * (including initially), and should return a MethodFactory to be used for the given log method, at the given level, - * for a logger with the given name. If you'd like to retain all the reliability and features of loglevel, it's - * recommended that this wraps the initially provided value of log.methodFactory + * Possible log level numbers. */ - methodFactory: MethodFactory; - - /** - * Output trace message to console. - * This will also include a full stack trace - * - * @param msg any data to log to the console - */ - trace(...msg: any[]): void; - - /** - * Output debug message to console including appropriate icons - * - * @param msg any data to log to the console - */ - debug(...msg: any[]): void; - - /** - * Output info message to console including appropriate icons - * - * @param msg any data to log to the console - */ - info(...msg: any[]): void; - - /** - * Output warn message to console including appropriate icons - * - * @param msg any data to log to the console - */ - warn(...msg: any[]): void; - - /** - * Output error message to console including appropriate icons - * - * @param msg any data to log to the console - */ - error(...msg: any[]): void; - - /** - * This disables all logging below the given level, so that after a log.setLevel("warn") call log.warn("something") - * or log.error("something") will output messages, but log.info("something") will not. - * - * @param level as a string, like 'error' (case-insensitive) or as a number from 0 to 5 (or as log.levels. values) - * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling - * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass - * false as the optional 'persist' second argument, persistence will be skipped. - */ - setLevel( - level: - LogLevelNumbers - | 'trace' - | 'debug' - | 'info' - | 'warn' - | 'error' - | 'silent' - | keyof LogLevel, - persist?: boolean - ): void; - - /** - * If you're using another JavaScript library that exposes a 'log' global, you can run into conflicts with loglevel. - * Similarly to jQuery, you can solve this by putting loglevel into no-conflict mode immediately after it is loaded - * onto the page. This resets to 'log' global to its value before loglevel was loaded (typically undefined), and - * returns the loglevel object, which you can then bind to another name yourself. - */ - noConflict(): any; - - /** - * Returns the current logging level, as a value from LogLevel. - * It's very unlikely you'll need to use this for normal application logging; it's provided partly to help plugin - * development, and partly to let you optimize logging code as below, where debug data is only generated if the - * level is set such that it'll actually be logged. This probably doesn't affect you, unless you've run profiling - * on your code and you have hard numbers telling you that your log data generation is a real performance problem. - */ - getLevel(): LogLevel[keyof LogLevel]; - - /** - * This sets the current log level only if one has not been persisted and can’t be loaded. This is useful when - * initializing scripts; if a developer or user has previously called setLevel(), this won’t alter their settings. - * For example, your application might set the log level to error in a production environment, but when debugging - * an issue, you might call setLevel("trace") on the console to see all the logs. If that error setting was set - * using setDefaultLevel(), it will still say as trace on subsequent page loads and refreshes instead of resetting - * to error. - * - * The level argument takes is the same values that you might pass to setLevel(). Levels set using - * setDefaultLevel() never persist to subsequent page loads. - * - * @param level as the value from the enum - */ - setDefaultLevel(level: LogLevel): void; - - /** - * This gets you a new logger object that works exactly like the root log object, but can have its level and - * logging methods set independently. All loggers must have a name (which is a non-empty string). Calling - * getLogger() multiple times with the same name will return an identical logger object. - * In large applications, it can be incredibly useful to turn logging on and off for particular modules as you are - * working with them. Using the getLogger() method lets you create a separate logger for each part of your - * application with its own logging level. Likewise, for small, independent modules, using a named logger instead - * of the default root logger allows developers using your module to selectively turn on deep, trace-level logging - * when trying to debug problems, while logging only errors or silencing logging altogether under normal - * circumstances. - * @param name The name of the produced logger - */ - getLogger(name: string): Logger; - - /** - * This enables all log messages, and is equivalent to log.setLevel("trace"). - * - * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling - * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass - * false as the optional 'persist' second argument, persistence will be skipped. - */ - enableAll(persist?: boolean): void; - - /** - * This disables all log messages, and is equivalent to log.setLevel("silent"). - * - * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling - * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass - * false as the optional 'persist' second argument, persistence will be skipped. - */ - disableAll(persist?: boolean): void; + type LogLevelNumbers = LogLevel[keyof LogLevel]; + + type LoggingMethod = (...message: any[]) => void; + + type MethodFactory = (methodName: string, level: LogLevelNumbers, loggerName: string) => LoggingMethod; + + interface Logger { + /** + * Available log levels. + */ + readonly levels: LogLevel; + + /** + * Plugin API entry point. This will be called for each enabled method each time the level is set + * (including initially), and should return a MethodFactory to be used for the given log method, at the given level, + * for a logger with the given name. If you'd like to retain all the reliability and features of loglevel, it's + * recommended that this wraps the initially provided value of log.methodFactory + */ + methodFactory: MethodFactory; + + /** + * Output trace message to console. + * This will also include a full stack trace + * + * @param msg any data to log to the console + */ + trace(...msg: any[]): void; + + /** + * Output debug message to console including appropriate icons + * + * @param msg any data to log to the console + */ + debug(...msg: any[]): void; + + /** + * Output info message to console including appropriate icons + * + * @param msg any data to log to the console + */ + info(...msg: any[]): void; + + /** + * Output warn message to console including appropriate icons + * + * @param msg any data to log to the console + */ + warn(...msg: any[]): void; + + /** + * Output error message to console including appropriate icons + * + * @param msg any data to log to the console + */ + error(...msg: any[]): void; + + /** + * This disables all logging below the given level, so that after a log.setLevel("warn") call log.warn("something") + * or log.error("something") will output messages, but log.info("something") will not. + * + * @param level as a string, like 'error' (case-insensitive) or as a number from 0 to 5 (or as log.levels. values) + * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling + * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass + * false as the optional 'persist' second argument, persistence will be skipped. + */ + setLevel( + level: + LogLevelNumbers + | 'trace' + | 'debug' + | 'info' + | 'warn' + | 'error' + | 'silent' + | keyof LogLevel, + persist?: boolean + ): void; + + /** + * If you're using another JavaScript library that exposes a 'log' global, you can run into conflicts with loglevel. + * Similarly to jQuery, you can solve this by putting loglevel into no-conflict mode immediately after it is loaded + * onto the page. This resets to 'log' global to its value before loglevel was loaded (typically undefined), and + * returns the loglevel object, which you can then bind to another name yourself. + */ + noConflict(): any; + + /** + * Returns the current logging level, as a value from LogLevel. + * It's very unlikely you'll need to use this for normal application logging; it's provided partly to help plugin + * development, and partly to let you optimize logging code as below, where debug data is only generated if the + * level is set such that it'll actually be logged. This probably doesn't affect you, unless you've run profiling + * on your code and you have hard numbers telling you that your log data generation is a real performance problem. + */ + getLevel(): LogLevel[keyof LogLevel]; + + /** + * This sets the current log level only if one has not been persisted and can’t be loaded. This is useful when + * initializing scripts; if a developer or user has previously called setLevel(), this won’t alter their settings. + * For example, your application might set the log level to error in a production environment, but when debugging + * an issue, you might call setLevel("trace") on the console to see all the logs. If that error setting was set + * using setDefaultLevel(), it will still say as trace on subsequent page loads and refreshes instead of resetting + * to error. + * + * The level argument takes is the same values that you might pass to setLevel(). Levels set using + * setDefaultLevel() never persist to subsequent page loads. + * + * @param level as the value from the enum + */ + setDefaultLevel(level: LogLevel): void; + + /** + * This gets you a new logger object that works exactly like the root log object, but can have its level and + * logging methods set independently. All loggers must have a name (which is a non-empty string). Calling + * getLogger() multiple times with the same name will return an identical logger object. + * In large applications, it can be incredibly useful to turn logging on and off for particular modules as you are + * working with them. Using the getLogger() method lets you create a separate logger for each part of your + * application with its own logging level. Likewise, for small, independent modules, using a named logger instead + * of the default root logger allows developers using your module to selectively turn on deep, trace-level logging + * when trying to debug problems, while logging only errors or silencing logging altogether under normal + * circumstances. + * @param name The name of the produced logger + */ + getLogger(name: string): Logger; + + /** + * This enables all log messages, and is equivalent to log.setLevel("trace"). + * + * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling + * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass + * false as the optional 'persist' second argument, persistence will be skipped. + */ + enableAll(persist?: boolean): void; + + /** + * This disables all log messages, and is equivalent to log.setLevel("silent"). + * + * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling + * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass + * false as the optional 'persist' second argument, persistence will be skipped. + */ + disableAll(persist?: boolean): void; + } } diff --git a/types/loglevel/test/loglevel-tests.ts b/types/loglevel/test/loglevel-tests.ts index 351de4cf67..453f81d28d 100644 --- a/types/loglevel/test/loglevel-tests.ts +++ b/types/loglevel/test/loglevel-tests.ts @@ -25,7 +25,7 @@ moduleLog.disableAll(); const logLevel = moduleLog.getLevel(); -const testLogger = moduleLog.getLogger('TestLogger'); +const testLogger: moduleLog.Logger = moduleLog.getLogger('TestLogger'); testLogger.setLevel(logLevel); testLogger.warn('logging test'); diff --git a/types/loglevel/test/loglevel-umd-tests.ts b/types/loglevel/test/loglevel-umd-tests.ts index a052f7cc53..97e9fe617a 100644 --- a/types/loglevel/test/loglevel-umd-tests.ts +++ b/types/loglevel/test/loglevel-umd-tests.ts @@ -21,7 +21,7 @@ log.disableAll(); const logLevel = log.getLevel(); -const testLogger = log.getLogger("TestLogger"); +const testLogger: log.Logger = log.getLogger("TestLogger"); testLogger.setLevel(logLevel); testLogger.warn("logging test"); From 32fdc3b1c30f31bb922684580702e6cd98a7f711 Mon Sep 17 00:00:00 2001 From: HenriqueCaires Date: Wed, 27 Sep 2017 17:46:41 -0300 Subject: [PATCH 005/127] Add timeout option (#19951) --- types/dropzone/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/dropzone/index.d.ts b/types/dropzone/index.d.ts index 18a70ca7fb..f809f84227 100644 --- a/types/dropzone/index.d.ts +++ b/types/dropzone/index.d.ts @@ -31,6 +31,7 @@ declare namespace Dropzone { url?: string; method?: string; withCredentials?: boolean; + timeout?: number; parallelUploads?: number; uploadMultiple?: boolean; maxFilesize?: number; From 37197f5ec6d64ee7dd884fb7b48c8d60439e7a59 Mon Sep 17 00:00:00 2001 From: Gustav Bylund Date: Wed, 27 Sep 2017 22:47:16 +0200 Subject: [PATCH 006/127] Update Navbar.d.ts (#19878) navExpanded was renamed to expanded in https://github.com/react-bootstrap/react-bootstrap/commit/f9ea411 --- types/react-bootstrap/lib/Navbar.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-bootstrap/lib/Navbar.d.ts b/types/react-bootstrap/lib/Navbar.d.ts index fdacbef45f..5231c74052 100644 --- a/types/react-bootstrap/lib/Navbar.d.ts +++ b/types/react-bootstrap/lib/Navbar.d.ts @@ -17,7 +17,7 @@ declare namespace Navbar { fixedTop?: boolean; fluid?: boolean; inverse?: boolean; - navExpanded?: boolean; + expanded?: boolean; onToggle?: Function; staticTop?: boolean; toggleButton?: any; // TODO: Add more specific type From a5ec9279430211a3c2e93701bbe3ab1b52cd74c6 Mon Sep 17 00:00:00 2001 From: Shenghan Gao Date: Wed, 27 Sep 2017 13:47:36 -0700 Subject: [PATCH 007/127] fix some semicolon issues for elasticsearch (#19965) --- types/elasticsearch/index.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/types/elasticsearch/index.d.ts b/types/elasticsearch/index.d.ts index fbe9795b9e..8acc7e4097 100644 --- a/types/elasticsearch/index.d.ts +++ b/types/elasticsearch/index.d.ts @@ -113,9 +113,9 @@ declare module Elasticsearch { } export interface Explanation { - value: number, - description: string, - details: Explanation[] + value: number; + description: string; + details: Explanation[]; } export interface GenericParams { @@ -543,7 +543,7 @@ declare module Elasticsearch { inline: string; lang: string; } - } + }; } export interface ReindexResponse { @@ -555,7 +555,7 @@ declare module Elasticsearch { retries: { bulk: number; search: number; - } + }; throttled_millis: number; failures: any[]; } @@ -1073,7 +1073,7 @@ declare module Elasticsearch { tokenizer?: string; explain?: boolean; attributes?: NameList; - format?: "" + format?: ""; } export interface IndicesClearCacheParams extends GenericParams { @@ -1370,7 +1370,7 @@ declare module Elasticsearch { masterTimeout?: TimeSpan; body: { actions: IndicesUpdateAliasesParamsAction[]; - } + }; } export interface IndicesUpdateAliasesParamsAction { @@ -1386,7 +1386,7 @@ declare module Elasticsearch { }; remove_index?: { index: string; - } + }; } export interface IndicesUpgradeParams extends GenericParams { From 91d1850785ad26b2ddb17347218066bf805df5ad Mon Sep 17 00:00:00 2001 From: fmmoret Date: Wed, 27 Sep 2017 19:06:29 -0700 Subject: [PATCH 008/127] Fix types on LayoutAnimation .easeInEaseOut, .linear, and .spring have LayoutAnimationConfigs bound already. See https://github.com/facebook/react-native/blob/master/Libraries/LayoutAnimation/LayoutAnimation.js#L164 --- types/react-native/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 9f191d1485..ba4ed92498 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -533,9 +533,9 @@ export interface LayoutAnimationStatic { linear: LayoutAnimationConfig spring: LayoutAnimationConfig } - easeInEaseOut: (config: LayoutAnimationConfig, onAnimationDidEnd?: () => void) => void - linear: (config: LayoutAnimationConfig, onAnimationDidEnd?: () => void) => void - spring: (config: LayoutAnimationConfig, onAnimationDidEnd?: () => void) => void + easeInEaseOut: (onAnimationDidEnd?: () => void) => void + linear: (onAnimationDidEnd?: () => void) => void + spring: (onAnimationDidEnd?: () => void) => void } type FlexAlignType = "flex-start" | "flex-end" | "center" | "stretch" | "baseline"; From dbeac07ba4a231d1056d80076a58c19c10881028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miika=20H=C3=A4nninen?= Date: Thu, 28 Sep 2017 10:41:32 +0300 Subject: [PATCH 009/127] Update big.js definitions for version 4.0.0 (#20096) --- types/big.js/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/big.js/index.d.ts b/types/big.js/index.d.ts index 3559dda9ca..cf197e8cfc 100644 --- a/types/big.js/index.d.ts +++ b/types/big.js/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for big.js 3.2 +// Type definitions for big.js 4.0 // Project: https://github.com/MikeMcl/big.js/ // Definitions by: Steve Ognibene // Miika Hänninen @@ -89,14 +89,14 @@ export interface BigConstructor { * -1e+6 to 0 inclusive * Default value: -7 */ - E_NEG: number; + NE: number; /** * The positive exponent value at and above which toString returns exponential notation. * * 0 to 1e+6 inclusive * Default value: 21 */ - E_POS: number; + PE: number; } export interface Big { From a5bb2d814e3b9c7299584a65bc312392330c67da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Thu, 28 Sep 2017 16:28:36 +0200 Subject: [PATCH 010/127] [react-tracking] Update for v5 and use Pick over Partial. --- types/react-tracking/index.d.ts | 8 ++++---- .../test/react-tracking-with-types-tests.tsx | 10 +++++++--- .../test/react-tracking-without-types-tests.tsx | 2 +- types/react-tracking/tslint.json | 3 ++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/types/react-tracking/index.d.ts b/types/react-tracking/index.d.ts index 8998c1dbb9..b94e830559 100644 --- a/types/react-tracking/index.d.ts +++ b/types/react-tracking/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-tracking 4.2 +// Type definitions for react-tracking 5.0 // Project: https://github.com/NYTimes/react-tracking // Definitions by: Eloy Durán // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -50,7 +50,7 @@ interface Options { process?(ownTrackingData: T): T | Falsy; } -export type TrackingInfo = T | ((props: P) => T); +export type TrackingInfo = T | ((props: P, state: S) => T); // Duplicated from ES6 lib to remove the `void` typing, otherwise `track` can’t be used as a HOC function that passes // through a JSX component that be used without casting. @@ -64,8 +64,8 @@ type Decorator = ClassDecorator & MethodDecorator; * * For examples of such extensions see: https://github.com/artsy/reaction/blob/master/src/utils/track.ts */ -export interface Track { - (trackingInfo?: TrackingInfo, P>, options?: Options>): Decorator; +export interface Track { + (trackingInfo?: TrackingInfo, P, S>, options?: Options>): Decorator; } export const track: Track; diff --git a/types/react-tracking/test/react-tracking-with-types-tests.tsx b/types/react-tracking/test/react-tracking-with-types-tests.tsx index 0952dfa8c6..76c9ccb5b5 100644 --- a/types/react-tracking/test/react-tracking-with-types-tests.tsx +++ b/types/react-tracking/test/react-tracking-with-types-tests.tsx @@ -8,25 +8,29 @@ interface Props { tracking?: TrackingProp; } +interface State { + isClicked: boolean; +} + interface TrackingData { page: string; event: string; } -const track: Track = _track; +const track: Track = _track; @track({ page: "ClassPage" }, { dispatch: customEventReporter, dispatchOnMount: contextData => ({ event: "pageDataReady" }), process: ownTrackingData => ownTrackingData.page ? { event: 'pageview' } : null, }) -class ClassPage extends React.Component { +class ClassPage extends React.Component { @track({ event: "Clicked" }) handleClick() { // ... other stuff } - @track(props => ({ event: `got ${props.someProp}` })) + @track((props, state) => ({ event: `got ${props.someProp} and clicked ${state.isClicked}` })) render() { return (