ts-pattern
ts-pattern copied to clipboard
Wrong type with Pattern#when
Describe the bug I try to use ts-pattern with fp-ts when I use P.when(some_type_guard_function) is has not expected type
Code Sandbox with a minimal reproduction case the ts version of codesandbox editor is not support 4.7 yet
here is some case, I don't know what happen


but when I change the guard function signature to (fa: any) => fa is Some<number>
or (fa: unknown) => fa is Some<number>
, it will work!!


It has same problem when input type is string | number



but Tuple or Object can work

and I known match().when()
always correct.
Versions
- TypeScript version: 4.7.2
- ts-pattern version: 4.0.2
- environment: chrome
there is another case

It does not work.
but, look at the type Data
, when I delete value
property or make it to optional, work again !!


here is my tsconfig.json
{
"compilerOptions": {
/* Projects */
"incremental": true,
/* Language and Environment */
"target": "es6",
"lib": ["dom", "esnext"],
"jsx": "react-jsx",
/* Modules */
"module": "commonjs",
"baseUrl": "./src",
"paths": {
"@/*": ["./*"]
},
"rootDirs": ["./src", "./package.json"],
"types": ["node", "jest"],
"resolveJsonModule": true,
/* Emit */
"noEmit": true,
"sourceMap": true,
"importsNotUsedAsValues": "error",
/* Interop Constraints */
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
/* Type Checking */
"strictNullChecks": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitAny": false,
"noImplicitThis": true,
"useUnknownInCatchVariables": true,
"noUncheckedIndexedAccess": true,
/* Completeness */
"skipLibCheck": true
},
"exclude": ["node_modules", "src/libs"],
"include": ["src"]
}
Hey! Thanks for the report, do you mind creating a TypeScript playground example demonstrating the issue you are facing so I can investigate later? it seems like you can import ts-pattern and fp-ts in there: Playground Example
Hey! Thanks for the report, do you mind creating a TypeScript playground example demonstrating the issue you are facing so I can investigate later? it seems like you can import ts-pattern and fp-ts in there: Playground Example
Wowww I didn't known I can import npm package in TypeScript Playground.
this is first comment show case: Comment One Case
second comment show case: Comment Two Case
Thanks for the playgrounds. Sorry I didn't have the time to look into it yet, I'll try to find some time this weekend
never mind. I tried another way to write my code