From: Evan You Date: Tue, 22 Oct 2019 03:37:03 +0000 (-0400) Subject: types: improve types X-Git-Tag: v3.0.0-alpha.0~346 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a25b1371ab183d51bb4ab6388ca138fbbce20c60;p=thirdparty%2Fvuejs%2Fcore.git types: improve types --- diff --git a/packages/runtime-core/src/apiOptions.ts b/packages/runtime-core/src/apiOptions.ts index ad1c29b437..780522074b 100644 --- a/packages/runtime-core/src/apiOptions.ts +++ b/packages/runtime-core/src/apiOptions.ts @@ -368,7 +368,7 @@ export function applyOptions( function callSyncHook( name: 'beforeCreate' | 'created', options: ComponentOptions, - ctx: any, + ctx: ComponentPublicInstance, globalMixins: ComponentOptions[] ) { callHookFromMixins(name, globalMixins, ctx) @@ -389,7 +389,7 @@ function callSyncHook( function callHookFromMixins( name: 'beforeCreate' | 'created', mixins: ComponentOptions[], - ctx: any + ctx: ComponentPublicInstance ) { for (let i = 0; i < mixins.length; i++) { const fn = mixins[i][name] diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index eccfdfb86d..b83e088492 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -33,14 +33,14 @@ export const hasOwn = ( ): key is keyof typeof val => hasOwnProperty.call(val, key) export const isArray = Array.isArray -export const isFunction = (val: any): val is Function => +export const isFunction = (val: unknown): val is Function => typeof val === 'function' -export const isString = (val: any): val is string => typeof val === 'string' -export const isSymbol = (val: any): val is symbol => typeof val === 'symbol' -export const isObject = (val: any): val is Record => +export const isString = (val: unknown): val is string => typeof val === 'string' +export const isSymbol = (val: unknown): val is symbol => typeof val === 'symbol' +export const isObject = (val: unknown): val is Record => val !== null && typeof val === 'object' -export function isPromise(val: any): val is Promise { +export function isPromise(val: unknown): val is Promise { return isObject(val) && isFunction(val.then) && isFunction(val.catch) } @@ -48,7 +48,7 @@ export const objectToString = Object.prototype.toString export const toTypeString = (value: unknown): string => objectToString.call(value) -export const isPlainObject = (val: any): val is object => +export const isPlainObject = (val: unknown): val is object => toTypeString(val) === '[object Object]' export const isReservedProp = (key: string): boolean =>