Skip to content

Commit

Permalink
fix(devOrProd): 类型设置默认值
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Oct 20, 2021
1 parent b8f20ce commit 4f6784d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/utils/devOrProd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ describe('devOrProd', () => {
test('正确推导类型', () => {
const obj: {
x: 'ppp' | 'ff' | '00'
y: string
} = {
x: devOrProd('00', () => 'ff'),
y: devOrProd<string>('1', '3').replace('11', '333'),
}
expect(obj).toBe(obj)
})
Expand Down
2 changes: 1 addition & 1 deletion src/utils/devOrProd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @param devValue 开发环境返回的值或调用的函数
* @param prodValue 生产环境返回的值或调用的函数
*/
export function devOrProd<R, T extends R, F extends () => R>(
export function devOrProd<R, T extends R = R, F extends () => R = () => R>(
devValue: T | F,
prodValue: T | F,
): R {
Expand Down

0 comments on commit 4f6784d

Please sign in to comment.