From 9bd346b110655b82d81442f2ba366f53299a71a4 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 2 Oct 2017 15:48:08 -0700 Subject: [PATCH] Strict function variance fixes round 1, stage 3 --- types/jquery/index.d.ts | 4 ++-- types/jquery/test/example-tests.ts | 4 ++-- types/jquery/test/longdesc-tests.ts | 2 +- types/ramda/index.d.ts | 4 ++-- types/ramda/ramda-tests.ts | 27 ++++++++++-------------- types/react-native/test/index.tsx | 2 +- types/react-redux/react-redux-tests.tsx | 3 ++- types/sharepoint/sharepoint-tests.ts | 28 ++++++++++++++++--------- types/webpack/webpack-tests.ts | 2 +- 9 files changed, 40 insertions(+), 36 deletions(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 4a835896ed..e557103e47 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -85,7 +85,7 @@ interface JQueryStatic { * @since 1.3 */ off: boolean; - step: JQuery.PlainObject>; + step: JQuery.PlainObject>; }; /** * A Promise-like object (or "thenable") that resolves when the document is ready. @@ -4754,7 +4754,7 @@ interface JQuery extends Iterable * @see {@link https://api.jquery.com/queue/} * @since 1.2 */ - queue(queueName?: string): JQuery.Queue; + queue(queueName?: string): JQuery.Queue; /** * Specify a function to execute when the DOM is fully loaded. * diff --git a/types/jquery/test/example-tests.ts b/types/jquery/test/example-tests.ts index 5d4e27d970..f32a2c3723 100644 --- a/types/jquery/test/example-tests.ts +++ b/types/jquery/test/example-tests.ts @@ -3061,7 +3061,7 @@ function examples() { type: 'dog', // Note that event comes *after* one and two - test: function(one: typeof you, two: typeof they, event: JQuery.Event) { + test: function(one: typeof you, two: typeof they, event: JQuery.Event) { $('#log') // `one` maps to `you`, the 1st additional @@ -3081,7 +3081,7 @@ function examples() { // The clicked element is `event.target`, // and its type is "button" - .append('the ' + event.target.type + '.'); + .append('the ' + (event.target as HTMLButtonElement).type + '.'); }, }; diff --git a/types/jquery/test/longdesc-tests.ts b/types/jquery/test/longdesc-tests.ts index d77823ff78..bf63445c16 100644 --- a/types/jquery/test/longdesc-tests.ts +++ b/types/jquery/test/longdesc-tests.ts @@ -1332,7 +1332,7 @@ function longdesc() { function jquery_css_hooks_6() { $.fx.step.someCSSProp = function(fx) { - $.cssHooks.someCSSProp.set(fx.elem, fx.now + fx.unit); + $.cssHooks.someCSSProp.set(fx.elem as HTMLElement, fx.now + fx.unit); }; } diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index c538d555a0..1d46d88495 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -225,9 +225,9 @@ declare namespace R { /** * Returns a new list containing the contents of the given list, followed by the given element. */ + append(el: U): (list: T[]) => Array<(T & U)>; append(el: U, list: T[]): Array<(T & U)>; - append(el: U): (list: T[]) => Array<(T & U)>; - append(el: U): (list: T[]) => Array<(T & U)>; + append(el: T, list: string): Array; /** * Applies function fn to the argument list args. This is useful for creating a fixed-arity function from diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 0998930d42..7ecd3e5f60 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -151,9 +151,9 @@ class F2 { }; () => { - const truncate = R.when( + const truncate = R.when( R.propSatisfies(R.flip(R.gt)(10), "length"), - R.pipe(R.take(10), R.append("…"), R.join("")) + R.pipe(R.take(10), R.append("…") as (wrong: any) => string[], R.join("")) ); const a: string = truncate("12345"); // => '12345' const b: string = truncate("0123456789ABC"); // => '0123456789…' @@ -317,8 +317,7 @@ R.times(i, 5); (() => { const numbers = [1, 2, 3]; - const add = (a: number, b: number) => a + b; - R.reduce(add, 10, numbers); // => 16; + R.reduce((a,b) => a + b, 10, numbers); // => 16; })(); (() => { @@ -326,7 +325,7 @@ R.times(i, 5); })(); (() => { - const pairs = [["a", 1], ["b", 2], ["c", 3]]; + const pairs = [["a", 1], ["b", 2], ["c", 3]] as [string, number][]; function flattenPairs(pair: [string, number], acc: Array): Array { return acc.concat(pair); @@ -854,13 +853,9 @@ interface Obj { () => { const numbers = [1, 2, 3]; - function add(a: number, b: number) { - return a + b; - } - - R.reduce(add, 10, numbers); // => 16 + R.reduce((a,b) => a + b, 10, numbers); // => 16 R.reduce(add)(10, numbers); // => 16 - R.reduce(add, 10)(numbers); // => 16 + R.reduce((a,b) => a + b, 10)(numbers); // => 16 }; interface Student { @@ -1086,7 +1081,7 @@ type Pair = KeyValuePair; R.transduce(transducer, fn, [], numbers); // => [2, 3] R.transduce(transducer, fn, [])(numbers); // => [2, 3] R.transduce(transducer, fn)([], numbers); // => [2, 3] - R.transduce(transducer)(fn, [], numbers); // => [2, 3] + R.transduce(transducer)(fn, [], numbers); // => [2, 3] }; () => { @@ -1101,7 +1096,7 @@ type Pair = KeyValuePair; const list = [1, 2, 3]; R.traverse(of, fn, list); R.traverse(of, fn)(list); - R.traverse(of)(fn, list); + R.traverse(of)(fn, list); }; () => { @@ -1691,7 +1686,7 @@ class Rectangle { const format = R.converge( R.call, [ - R.pipe(R.prop("indent"), indentN), + R.pipe<{}, number, (s: string) => string>(R.prop("indent"), indentN), R.prop("value") ] ); @@ -1841,7 +1836,7 @@ class Rectangle { }; () => { - const sortByAgeDescending = R.sortBy(R.compose(R.negate, R.prop("age"))); + const sortByAgeDescending = R.sortBy(R.compose<{}, number, number>(R.negate, R.prop("age"))); const alice = { name: "ALICE", age : 101 @@ -1859,7 +1854,7 @@ class Rectangle { }; () => { - const sortByNameCaseInsensitive = R.sortBy(R.compose(R.toLower, R.prop("name"))); + const sortByNameCaseInsensitive = R.sortBy(R.compose(R.toLower, R.prop("name"))); const alice = { name: "ALICE", age : 101 diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 9771db9bc9..92e349be14 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -297,7 +297,7 @@ class ScrollerListComponentTest extends React.Component<{}, { dataSource: ListVi return }} - renderRow={({ type, data }, _, row: number) => { + renderRow={({ type, data }, _, row) => { return Filler } } /> diff --git a/types/react-redux/react-redux-tests.tsx b/types/react-redux/react-redux-tests.tsx index c52d40d0aa..0a00bc1250 100644 --- a/types/react-redux/react-redux-tests.tsx +++ b/types/react-redux/react-redux-tests.tsx @@ -381,6 +381,7 @@ interface DispatchProps { declare var actionCreators: () => { action: Function; } +declare var dispatchActionCreators: () => DispatchProps; declare var addTodo: () => { type: string; }; declare var todoActionCreators: { [type: string]: (...args: any[]) => any; }; declare var counterActionCreators: { [type: string]: (...args: any[]) => any; }; @@ -521,7 +522,7 @@ function mergeProps(stateProps: TodoState, dispatchProps: DispatchProps, ownProp }); } -connect(mapStateToProps2, actionCreators, mergeProps)(MyRootComponent); +connect(mapStateToProps2, dispatchActionCreators, mergeProps)(MyRootComponent); //https://github.com/DefinitelyTyped/DefinitelyTyped/issues/14622#issuecomment-279820358 diff --git a/types/sharepoint/sharepoint-tests.ts b/types/sharepoint/sharepoint-tests.ts index 8d62972490..b41c38f97d 100644 --- a/types/sharepoint/sharepoint-tests.ts +++ b/types/sharepoint/sharepoint-tests.ts @@ -530,7 +530,8 @@ namespace CSR { .onPreRender(hookFormContext) .onPostRender(fixCsrCustomLayout); - function hookFormContext(ctx: FormRenderContexWithHook) { + function hookFormContext(preRenderContext: SPClientTemplates.RenderContext /* FormRenderContexWithHook */) { + let ctx = preRenderContext as FormRenderContexWithHook; if (ctx.ControlMode === SPClientTemplates.ClientControlMode.EditForm || ctx.ControlMode === SPClientTemplates.ClientControlMode.NewForm) { for (const fieldSchemaInForm of ctx.ListSchema.Field) { @@ -561,7 +562,8 @@ namespace CSR { } } - function fixCsrCustomLayout(ctx: SPClientTemplates.RenderContext_Form) { + function fixCsrCustomLayout(postRenderContext: SPClientTemplates.RenderContext /* SPClientTemplates.RenderContext_Form */) { + let ctx = postRenderContext as SPClientTemplates.RenderContext_Form; if (ctx.ControlMode === SPClientTemplates.ClientControlMode.Invalid || ctx.ControlMode === SPClientTemplates.ClientControlMode.View) { return; @@ -817,7 +819,8 @@ namespace CSR { } } }) - .onPostRenderField(fieldName, (schema: SPClientTemplates.FieldSchema_InForm_User, ctx) => { + .onPostRenderField(fieldName, (postRenderSchema, ctx) => { + let schema = postRenderSchema as SPClientTemplates.FieldSchema_InForm_User; if (ctx.ControlMode === SPClientTemplates.ClientControlMode.EditForm || ctx.ControlMode === SPClientTemplates.ClientControlMode.NewForm) { if (schema.Type === 'User' || schema.Type === 'UserMulti') { @@ -1148,7 +1151,9 @@ namespace CSR { computedValue(targetField: string, transform: (...values: string[]) => string, ...sourceField: string[]): CSR { const dependentValues: { [field: string]: string } = {}; - return this.onPostRenderField(targetField, (schema: SPClientTemplates.FieldSchema_InForm, ctx: SPClientTemplates.RenderContext_FieldInForm) => { + return this.onPostRenderField(targetField, (postRenderSchema, postRenderContext) => { + let schema = postRenderSchema as SPClientTemplates.FieldSchema_InForm; + let ctx = postRenderContext as SPClientTemplates.RenderContext_FieldInForm; if (ctx.ControlMode === SPClientTemplates.ClientControlMode.EditForm || ctx.ControlMode === SPClientTemplates.ClientControlMode.NewForm) { const targetControl = CSR.getControl(schema as SPClientTemplates.FieldSchema_InForm); @@ -1165,8 +1170,8 @@ namespace CSR { setInitialValue(fieldName: string, value: any, ignoreNull?: boolean): CSR { if (value || !ignoreNull) { - return this.onPreRenderField(fieldName, (schema, ctx: SPClientTemplates.RenderContext_FieldInForm) => { - ctx.ListData.Items[0][fieldName] = value; + return this.onPreRenderField(fieldName, (schema, ctx) => { + (ctx as SPClientTemplates.RenderContext_FieldInForm).ListData.Items[0][fieldName] = value; }); } else { return this; @@ -1335,8 +1340,9 @@ namespace CSR { } lookupAddNew(fieldName: string, prompt: string, showDialog?: boolean, contentTypeId?: string): CSR { - return this.onPostRenderField(fieldName, - (schema: SPClientTemplates.FieldSchema_InForm_Lookup, ctx: SPClientTemplates.RenderContext_FieldInForm) => { + return this.onPostRenderField(fieldName, (postRenderSchema, postRenderContext) => { + let schema = postRenderSchema as SPClientTemplates.FieldSchema_InForm_Lookup; + let ctx = postRenderContext as SPClientTemplates.RenderContext_FieldInForm; let control: HTMLInputElement; if (ctx.ControlMode === SPClientTemplates.ClientControlMode.EditForm || ctx.ControlMode === SPClientTemplates.ClientControlMode.NewForm) @@ -2271,7 +2277,8 @@ namespace SampleReputation { SP.SOD.registerSod('typescripttemplates.ts', '/SPTypeScript/Extensions/typescripttemplates.js'); SP.SOD.executeFunc('typescripttemplates.ts', 'CSR', () => { CSR.override(10004, 1) - .onPreRender((ctx: MyList) => { + .onPreRender(preRenderContext => { + let ctx = preRenderContext as MyList; ctx.listId = ctx.listName.substring(1, 37); }) .header('
    ') @@ -2287,7 +2294,8 @@ namespace SampleReputation { SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs('likes.js'); } - function renderTemplate(ctx: MyList) { + function renderTemplate(renderContext: SPClientTemplates.RenderContext) { + let ctx = renderContext as MyList; const rows = ctx.ListData.Row; let result = ''; for (const row of rows) { diff --git a/types/webpack/webpack-tests.ts b/types/webpack/webpack-tests.ts index b453e304b4..05c346f728 100644 --- a/types/webpack/webpack-tests.ts +++ b/types/webpack/webpack-tests.ts @@ -622,7 +622,7 @@ configuration = { performance, }; -function loader(this: webpack.loader.LoaderContext, source: string, sourcemap: string): void { +function loader(this: webpack.loader.LoaderContext, source: string | Buffer, sourcemap: string | Buffer): void { this.cacheable(); this.async();