You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
type RowMap = Record<string, unknown>;
type RowArray = unknown[];
type SyncRowTransform =
| ((row: RowArray) => RowArray)
| ((row: RowMap) => RowMap);
function myFunction(...): ... {
return fastCsv.format({
delimiter,
includeEndRowDelimiter: true,
// Please ignore the fact I have 3 duplicate `transform` keys here, this is
// only for demonstration purposes
transform: getTransformer(driver) as any,
// getTransformer is a function that I've omitted here, but it returns a `SyncRowTransform`
// The typing for `transform` doesn't seem to accept a `(A -> A) | (B -> B)`
// function and instead want a `(A | B) -> (A | B)` function. So an explicit cast
// here is necessary
transform: true ? t1 : t1,
// This type checks fine
transform: true ? t2 : t3,
// But this doesn't type check
// [tsserver 2322] [E] Type '((row: RowArray) => RowArray) | ((row: RowMap) => RowMap)' is not assignable to type 'RowTransformFunction<RowArray, RowArray> | undefined'.
// Type '(row: RowMap) => RowMap' is not assignable to type 'RowTransformFunction<RowArray, RowArray> | undefined'.
// Type '(row: RowMap) => RowMap' is not assignable to type 'SyncRowTransform<RowArray, RowArray>'.
// Types of parameters 'row' and 'row' are incompatible.
// Type 'RowArray' is not assignable to type 'RowMap'.
// Index signature for type 'string' is missing in type 'unknown[]'.
});
}
function t1(row: RowMap | RowArray): RowMap | RowArray {
return row;
}
function t2(row: RowArray): RowArray {
return row;
}
function t3(row: RowMap): RowMap {
return row;
}
Describe the solution you'd like
Support transform functions of the type
varun-dc
changed the title
[FEATURE] Support transform FormatterOptionsArgs of type 'A -> A | B -> B`
[FEATURE] Support transform FormatterOptionsArgs of type 'A -> A | B -> B'
Apr 11, 2022
Parsing or Formatting?
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
Support
transform
functions of the typeIf it's not going cause problems for everyone else using this package.
Describe alternatives you've considered
We can just do a hard cast to bypass the issue. It seems to work fine when I try it out locally in my project.
Additional comments
Could we potentially support
Where
A
isRowArray
andB
isRowMap
, so that we retain backward compatibility?The text was updated successfully, but these errors were encountered: