Skip to content

Commit

Permalink
chore: enable noImplicitAny (#692)
Browse files Browse the repository at this point in the history
fix #691
  • Loading branch information
aitboudad committed Feb 7, 2018
1 parent 7d7fc79 commit b29bc5d
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .config/webpack.test.js
Expand Up @@ -22,7 +22,7 @@ module.exports = {
},
{
test: /\.ts$/,
use: ['awesome-typescript-loader?inlineSourceMap=true&sourceMap=false&declaration=false', 'angular2-template-loader'],
use: ['awesome-typescript-loader?inlineSourceMap=true&configFileName=tsconfig-spec.json&sourceMap=false&declaration=false', 'angular2-template-loader'],
exclude: [/node_modules/]
},
{ test: /\.html$/, use: ['raw-loader'] },
Expand Down
2 changes: 1 addition & 1 deletion demo/src/tsconfig.app.json
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.json",
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015"
Expand Down
10 changes: 10 additions & 0 deletions demo/tsconfig.json
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noImplicitAny": false
},
"include": [
"../src/**/*.ts",
"src/**/*.ts"
]
}
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -9,8 +9,8 @@
"scripts": {
"contrib:add": "all-contributors add",
"contrib:generate": "all-contributors generate",
"lint": "tslint 'src/**/*.ts' 'demo/**/*.ts' -p tsconfig.json",
"lint:fix": "tslint --fix 'src/**/*.ts' 'app/**/*.ts' -p tsconfig.json",
"lint": "tslint -p tsconfig.json",
"lint:fix": "tslint --fix -p tsconfig.json",
"postinstall": "patch --forward node_modules/ng-packagr/lib/steps/ngc.js .config/ng-packagr.patch || true",
"commit": "npm run build && git-cz",
"prepublish": "npm run build",
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/components/formly.attributes.ts
Expand Up @@ -55,7 +55,7 @@ export class FormlyAttributes implements OnChanges {
return field.templateOptions[prop];
}

return field[prop] || '';
return (<any>field)[prop] || '';
}

private getStatementValue(statement: string) {
Expand Down
6 changes: 4 additions & 2 deletions src/core/src/components/formly.field.config.ts
@@ -1,6 +1,7 @@
import { FormGroup, AbstractControl, FormGroupDirective, NgForm } from '@angular/forms';
import { Subject } from 'rxjs/Subject';
import { Field } from './../templates/field';
import { Field } from '../templates/field';
import { TemplateManipulators } from '../services/formly.config';

export interface FormlyFieldConfig {
/**
Expand Down Expand Up @@ -32,7 +33,7 @@ export interface FormlyFieldConfig {
*/
validation?: {
messages?: {
[messageProperties: string]: string | ((error, field: FormlyFieldConfig) => string);
[messageProperties: string]: string | ((error: any, field: FormlyFieldConfig) => string);
};
show?: boolean;
[additionalProperties: string]: any;
Expand Down Expand Up @@ -175,6 +176,7 @@ export interface FormlyTemplateOptions {
click?: (field: FormlyFieldConfig, formControl: AbstractControl) => void;
change?: (field: FormlyFieldConfig, formControl: AbstractControl) => void;
keypress?: (field: FormlyFieldConfig, formControl: AbstractControl) => void;
templateManipulators?: TemplateManipulators;
[additionalProperties: string]: any;
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/src/components/formly.field.ts
Expand Up @@ -3,7 +3,7 @@ import {
ViewContainerRef, ViewChild, ComponentRef, ComponentFactoryResolver, SimpleChanges,
} from '@angular/core';
import { FormGroup, FormArray } from '@angular/forms';
import { FormlyConfig, TypeOption } from '../services/formly.config';
import { FormlyConfig, TypeOption, TemplateManipulators } from '../services/formly.config';
import { Field } from '../templates/field';
import { FORMLY_VALIDATORS, evalExpression, getFieldModel } from '../utils';
import { FormlyFieldConfig, FormlyFormOptions, FormlyValueChangeEvent } from './formly.field.config';
Expand Down Expand Up @@ -158,7 +158,7 @@ export class FormlyField implements OnInit, OnChanges, OnDestroy {
}

private getFieldWrappers(type: TypeOption) {
let templateManipulators = {
const templateManipulators: TemplateManipulators = {
preWrapper: [],
postWrapper: [],
};
Expand All @@ -178,7 +178,7 @@ export class FormlyField implements OnInit, OnChanges, OnDestroy {
return [...preWrappers, ...this.field.wrappers, ...postWrappers];
}

private mergeTemplateManipulators(source, target) {
private mergeTemplateManipulators(source: TemplateManipulators, target: TemplateManipulators) {
target = target || {};
if (target.preWrapper) {
source.preWrapper = source.preWrapper.concat(target.preWrapper);
Expand Down
17 changes: 11 additions & 6 deletions src/core/src/services/formly.config.ts
@@ -1,9 +1,9 @@
import { Injectable, Inject, InjectionToken } from '@angular/core';
import { ValidationErrors } from '@angular/forms';
import { ValidationErrors, FormGroup } from '@angular/forms';
import { FormlyGroup } from '../components/formly.group';
import { Field } from './../templates/field';
import { reverseDeepMerge } from './../utils';
import { FormlyFieldConfig } from '../components/formly.field.config';
import { FormlyFieldConfig, FormlyFormOptions } from '../components/formly.field.config';

export const FORMLY_CONFIG_TOKEN = new InjectionToken<FormlyConfig>('FORMLY_CONFIG_TOKEN');

Expand All @@ -20,7 +20,7 @@ export class FormlyConfig {
};
validators: { [name: string]: ValidatorOption } = {};
wrappers: { [name: string]: WrapperOption } = {};
messages: { [name: string]: string | ((error, field: FormlyFieldConfig) => string); } = {};
messages: { [name: string]: string | ((error: any, field: FormlyFieldConfig) => string); } = {};

templateManipulators: {
preWrapper: ManipulatorWrapper[];
Expand All @@ -31,7 +31,7 @@ export class FormlyConfig {
};

extras: {
fieldTransform?: any,
fieldTransform?: ((fields: FormlyFieldConfig[], model: any, form: FormGroup, options: FormlyFormOptions) => FormlyFieldConfig[])[],
showError?: (field: Field) => boolean;
} = {
fieldTransform: undefined,
Expand Down Expand Up @@ -165,7 +165,7 @@ export class FormlyConfig {
return this.validators[name];
}

addValidatorMessage(name: string, message: string | ((error, field: FormlyFieldConfig) => string)) {
addValidatorMessage(name: string, message: string | ((error: any, field: FormlyFieldConfig) => string)) {
this.messages[name] = message;
}

Expand Down Expand Up @@ -213,7 +213,7 @@ export interface ValidatorOption {

export interface ValidationMessageOption {
name: string;
message: string | ((error, field: FormlyFieldConfig) => string);
message: string | ((error: any, field: FormlyFieldConfig) => string);
}

export interface ManipulatorOption {
Expand All @@ -225,6 +225,11 @@ export interface ManipulatorWrapper {
(f: FormlyFieldConfig): string;
}

export interface TemplateManipulators {
preWrapper?: ManipulatorWrapper[];
postWrapper?: ManipulatorWrapper[];
}

export interface ConfigOption {
types?: TypeOption[];
wrappers?: WrapperOption[];
Expand Down
14 changes: 7 additions & 7 deletions src/core/src/services/formly.form.builder.ts
Expand Up @@ -111,7 +111,7 @@ export class FormlyFormBuilder {
});
}

private initFieldExpression(field: FormlyFieldConfig, model, options: FormlyFormOptions) {
private initFieldExpression(field: FormlyFieldConfig, model: any, options: FormlyFormOptions) {
if (field.expressionProperties) {
for (let key in field.expressionProperties as any) {
if (typeof field.expressionProperties[key] === 'string' || isFunction(field.expressionProperties[key])) {
Expand Down Expand Up @@ -153,7 +153,7 @@ export class FormlyFormBuilder {
}

private initFieldAsyncValidation(field: FormlyFieldConfig) {
let validators = [];
let validators: any = [];
if (field.asyncValidators) {
for (let validatorName in field.asyncValidators) {
if (validatorName !== 'validation') {
Expand All @@ -164,7 +164,7 @@ export class FormlyFormBuilder {
}

return new Promise((resolve) => {
return validator(control, field).then(result => {
return validator(control, field).then((result: boolean) => {
resolve(result ? null : {[validatorName]: true});
});
});
Expand All @@ -173,7 +173,7 @@ export class FormlyFormBuilder {
}
}
if (field.asyncValidators && Array.isArray(field.asyncValidators.validation)) {
field.asyncValidators.validation.forEach(validate => {
field.asyncValidators.validation.forEach((validate: any) => {
if (typeof validate === 'string') {
validators.push(this.formlyConfig.getValidator(validate).validation);
} else {
Expand All @@ -194,7 +194,7 @@ export class FormlyFormBuilder {
}

private initFieldValidation(field: FormlyFieldConfig) {
let validators = [];
let validators: any = [];
FORMLY_VALIDATORS
.filter(opt => (field.templateOptions && field.templateOptions[opt])
|| (field.expressionProperties && field.expressionProperties[`templateOptions.${opt}`]),
Expand Down Expand Up @@ -225,7 +225,7 @@ export class FormlyFormBuilder {
}

if (field.validators && Array.isArray(field.validators.validation)) {
field.validators.validation.forEach(validate => {
field.validators.validation.forEach((validate: any) => {
if (typeof validate === 'string') {
validators.push(this.formlyConfig.getValidator(validate).validation);
} else {
Expand Down Expand Up @@ -287,7 +287,7 @@ export class FormlyFormBuilder {
}
}

private getValidation(opt, value) {
private getValidation(opt: string, value: any) {
switch (opt) {
case 'required':
return Validators.required;
Expand Down
18 changes: 9 additions & 9 deletions src/core/src/utils.ts
Expand Up @@ -9,8 +9,8 @@ export function getFieldId(formId: string, options: FormlyFieldConfig, index: st

export function getKeyPath(field: {key?: string|string[], fieldGroup?: any, fieldArray?: any}): (string|number)[] {
/* We store the keyPath in the field for performance reasons. This function will be called frequently. */
if (field['_formlyKeyPath'] !== undefined) {
return field['_formlyKeyPath'];
if ((<any> field)['_formlyKeyPath'] !== undefined) {
return (<any> field)['_formlyKeyPath'];
}
let keyPath: (string|number)[] = [];
if (field.key) {
Expand All @@ -32,7 +32,7 @@ export function getKeyPath(field: {key?: string|string[], fieldGroup?: any, fiel
}
}
}
field['_formlyKeyPath'] = keyPath;
(<any> field)['_formlyKeyPath'] = keyPath;
return keyPath;
}

Expand Down Expand Up @@ -66,30 +66,30 @@ export function getFieldModel(model: any, field: FormlyFieldConfig, constructEmp
return value;
}

export function assignModelValue(model, path, value) {
export function assignModelValue(model: any, path: string | (string | number)[], value: any) {
if (typeof path === 'string') {
path = getKeyPath({key: path});
}

if (path.length > 1) {
const e = path.shift();
if (!model[e] || !isObject(model[e])) {
model[e] = isNaN(path[0]) ? {} : [];
model[e] = typeof path[0] === 'string' ? {} : [];
}
assignModelValue(model[e], path, value);
} else {
model[path[0]] = value;
}
}

export function getValueForKey(model, path) {
export function getValueForKey(model: any, path: string | (string | number)[]): any {
if (typeof path === 'string') {
path = getKeyPath({key: path});
}
if (path.length > 1) {
const e = path.shift();
if (!model[e]) {
model[e] = isNaN(path[0]) ? {} : [];
model[e] = typeof path[0] === 'string' ? {} : [];
}
return getValueForKey(model[e], path);
} else {
Expand All @@ -101,7 +101,7 @@ export function getKey(controlKey: string, actualKey: string) {
return actualKey ? actualKey + '.' + controlKey : controlKey;
}

export function reverseDeepMerge(dest, ...args) {
export function reverseDeepMerge(dest: any, ...args: any[]) {
args.forEach(src => {
for (let srcArg in src) {
if (isNullOrUndefined(dest[srcArg]) || isBlankString(dest[srcArg])) {
Expand Down Expand Up @@ -134,7 +134,7 @@ export function isFunction(value: any) {
return typeof(value) === 'function';
}

export function objAndSameType(obj1, obj2) {
export function objAndSameType(obj1: any, obj2: any) {
return isObject(obj1) && isObject(obj2) &&
Object.getPrototypeOf(obj1) === Object.getPrototypeOf(obj2);
}
Expand Down
1 change: 1 addition & 0 deletions src/ui-bootstrap/src/types/select.ts
Expand Up @@ -6,6 +6,7 @@ export class SelectOption {
value?: string;
group?: SelectOption[];
disabled?: boolean;
[key: string]: any;

constructor(label: string, value?: string, children?: SelectOption[]) {
this.label = label;
Expand Down
2 changes: 1 addition & 1 deletion src/ui-material/src/types/checkbox.ts
Expand Up @@ -25,7 +25,7 @@ export class FormlyFieldCheckbox extends FieldType implements AfterViewInit {
}

ngAfterViewInit() {
const formField = this.field['__formField__'];
const formField = (<any> this.field)['__formField__'];
if (formField) {
formField._control.focusMonitor([this.matCheckbox._inputElement.nativeElement]);

Expand Down
4 changes: 2 additions & 2 deletions src/ui-material/src/types/input.ts
Expand Up @@ -23,8 +23,8 @@ export class FormlyFieldInput extends FieldType implements OnInit {
}

ngOnInit() {
if (this.field['__formField__']) {
this.field['__formField__']._control = this.matInput;
if ((<any> this.field)['__formField__']) {
(<any> this.field)['__formField__']._control = this.matInput;
}
super.ngOnInit();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui-material/src/types/multicheckbox.ts
Expand Up @@ -32,7 +32,7 @@ export class FormlyFieldMultiCheckbox extends FieldType implements AfterViewInit
}

ngAfterViewInit() {
const formField = this.field['__formField__'];
const formField = (<any> this.field)['__formField__'];
if (formField) {
formField._control.focusMonitor(
this.matCheckboxes.map(matCheckbox => matCheckbox._inputElement.nativeElement),
Expand Down
2 changes: 1 addition & 1 deletion src/ui-material/src/types/radio.ts
Expand Up @@ -19,7 +19,7 @@ export class FormlyFieldRadio extends FieldType implements AfterViewInit {
}

ngAfterViewInit() {
const formField = this.field['__formField__'];
const formField = (<any>this.field)['__formField__'];
if (formField) {
formField._control.focusMonitor(
this.matRadioButtons.map(matRadioButton => matRadioButton._inputElement.nativeElement),
Expand Down
5 changes: 3 additions & 2 deletions src/ui-material/src/types/select.ts
Expand Up @@ -8,6 +8,7 @@ export class SelectOption {
value?: string;
group?: SelectOption[];
disabled?: boolean;
[key: string]: any;

constructor(label: string, value?: string, children?: SelectOption[]) {
this.label = label;
Expand Down Expand Up @@ -76,8 +77,8 @@ export class FormlyFieldSelect extends FieldType implements OnInit {
}

ngOnInit() {
if (this.field['__formField__']) {
this.field['__formField__']._control = this.matSelect;
if ((<any>this.field)['__formField__']) {
(<any> this.field)['__formField__']._control = this.matSelect;
}
super.ngOnInit();
}
Expand Down
8 changes: 4 additions & 4 deletions src/ui-material/src/wrappers/form-field.ts
Expand Up @@ -66,19 +66,19 @@ export class FormlyWrapperFormField extends FieldWrapper implements OnInit, OnDe
ngOnInit() {
this.focused = !!this.field.focus;
this.formField._control = this;
this.field['__formField__'] = this.formField;
(<any> this.field)['__formField__'] = this.formField;
if (this.to.floatPlaceholder) {
this.to.floatLabel = this.to.floatPlaceholder;
console.warn(`${this.field.key}: Passing 'floatPlaceholder' is deprecated, Use 'floatLabel' instead.`);
}
}

focusMonitor(elements = []) {
focusMonitor(elements: any[] = []) {
elements.map(element => {
takeUntil.call(
this._focusMonitor.monitor(element, this.renderer, false),
this.destroy$,
).subscribe(focusOrigin => {
).subscribe((focusOrigin: any) => {
if (this.focused !== !!focusOrigin) {
this.ngZone.run(() => {
this.focused = !!focusOrigin;
Expand All @@ -93,7 +93,7 @@ export class FormlyWrapperFormField extends FieldWrapper implements OnInit, OnDe
onContainerClick() {}

ngOnDestroy() {
delete this.field['__formField__'];
delete (<any> this.field)['__formField__'];
this.stateChanges.complete();
this.destroy$.complete();
}
Expand Down

0 comments on commit b29bc5d

Please sign in to comment.