function isString(test: any): test is string{
return typeof test === "string";
}
function example(foo: any){
if(isString(foo)){
console.log("it is a string" + foo);
console.log(foo.length); // string function
// 如下代码编译时会出错,运行时也会出错,因为 foo 是 string 不存在toExponential方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function timeStampTo13(value: number) { | |
if (`${value}`.length === 10) { | |
return value * 1000; | |
} | |
return value; | |
} | |
export function timeStampTo10(value: number) { | |
if (`${value}`.length === 13) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface ClientModel { | |
idCardFront: string; | |
} | |
export interface NewInter extends Omit<ClientModel, 'idCardFront'> { | |
idCardFront?: string; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isString(test: any): test is string{ | |
return typeof test === "string"; | |
} | |
function example(foo: any){ | |
if(isString(foo)){ | |
console.log("it is a string" + foo); | |
console.log(foo.length); // string function | |
// 如下代码编译时会出错,运行时也会出错,因为 foo 是 string 不存在toExponential方法 | |
console.log(foo.toExponential(2)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 在 swagger 中定义 response 需要新建一个 class。 但是从数据库里面查询出来的数据有些不需要返回。所以可以通过`class-transform` 进行清除 | |
// response class | |
import { ConsoleLogger } from '@nestjs/common'; | |
import { ApiProperty } from '@nestjs/swagger'; | |
import { Exclude, Expose, Transform } from 'class-transformer'; | |
@Exclude() | |
export class IBookDetailResponse { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 用于拦截指定API,返回一个移除"添加时"拦截器的函数 | |
type IStopInterceptor = () => void; | |
interface IInterceptorItem { | |
id: string; | |
interceptor: UniApp.InterceptorOptions, | |
} | |
class Interceptors { | |
private interceptors: Record<string, IInterceptorItem[]> = {}; |