-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
F.getWithDefault Coercion type problem #84
Comments
give type parameter to O.getWithDefault. O.getWithDefault<number>(0). |
@JUSTIVE Yes, I'm familiar with this solution, but I'd like to know if there's a way to improve this function to have this default behavior. |
@mattaiod you're issue above is because
As you see, the function would explicitly type Note, there are a lot of instances where you need to do this when using getWithDefault. For example, the following would be a type error because the default is
|
Maybe the |
Hello everyone, first : thanks for this incredible library, look like the best in functionnal programmin in Ts
In the basic example
I have an typescript error at the last line:
The only way I have to fix that is to explicit precise the type like:
O.getWithDefault(0 as number)(res) // → 30
The version not curried works:
O.getWithDefault(res, 0)
I guess it's not normal so what is the reason and the solution?
Here my .eslintrc :
{
"extends": "@antfu",
"plugins": [
"functional"
],
"rules": {
"@typescript-eslint/quotes": 0,
"no-console": "off",
"array-callback-return": "error",
"no-constructor-return": "error",
"no-duplicate-imports": "off",
"no-new-native-nonconstructor": "error",
"no-self-compare": "error",
"no-template-curly-in-string": "error",
"no-unused-private-class-members": "error",
"class-methods-use-this": "error",
"consistent-return": "error",
"default-case": "error",
"dot-notation": "error",
"eqeqeq": "error",
"init-declarations": "error",
"no-eq-null": "error",
"no-extend-native": "error",
"no-implicit-coercion": "error",
"@typescript-eslint/no-unused-vars": "off",
"no-implicit-globals": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-var": "error",
"prefer-object-spread": "error",
"require-await": "error",
"yoda": "error",
"explicit-function-return-type": "off"
}
}
tsconfig.json:
{
"compilerOptions": {
"noUnusedLocals": true,
"noUnusedParameters": true,
"baseUrl": ".",
"module": "ESNext",
"target": "ESNext",
"lib": [
"DOM",
"ESNext",
"WebWorker"
],
"strict": true,
"esModuleInterop": true,
"jsx": "preserve",
"skipLibCheck": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"incremental": false,
"noImplicitOverride": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"alwaysStrict": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"useUnknownInCatchVariables": true,
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"noUncheckedIndexedAccess": true,
"noPropertyAccessFromIndexSignature": true,
"noFallthroughCasesInSwitch": true,
"exactOptionalPropertyTypes": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"allowJs": false,
"forceConsistentCasingInFileNames": true,
"types": [
"vitest",
"vite/client",
"vue/ref-macros",
"vite-plugin-pages/client",
"vite-plugin-vue-layouts/client",
],
"paths": {
"~/": [
"src/"
]
}
},
"exclude": [
"dist",
"node_modules",
"cypress",
"auto-imports.d.ts"
]
}
Thank you in advance for your attention
The text was updated successfully, but these errors were encountered: