Comments (4)
Yeah that looks like a reasonable solution.
Just to provide some clarity about the tests - while the 'as const' does wrap the whole tuple of tuples; since test.each is iterating through the first array; the function will end up acting on either - which is why it ends up in a union type. Though really I was just trying to create another function with the same usage as fromJS. (I never call it with a second arg).
I think the generation of a full union type is correct; but the fact that this breaks polymorphic functions seems to be the bug in TypeScript.
from immutable-js.
Real world just-upgrade breaking test suite: reactive/data-client#2424 CI: https://app.circleci.com/pipelines/github/data-client/rest-hooks/9617/workflows/48caf48a-179e-4b43-a1db-a1388047347a/jobs/61606
from immutable-js.
I tried some things, and it's kind of funny (or weird)
import { fromJS } from 'immutable';
const create = [(data: any) => data, fromJS][1];
create({}); // do error
const create2 = [fromJS][0];
create2({}); // works fine
const create3 =([(data: any) => data, fromJS] as const)[1];
create3({}); // works fine
const create4 = [(data: any, useless = undefined) => data, fromJS][1];
create4({}); // works fine
In the first example, the created array has a type like (function1|function2)[]
, while the second has a function1[]
type and the last one is the tuple [function1, function2]
.
I see in your test stack that you already use a as const
, but it seems that by passing the createInput
function as a second parameter, it seems to force fromJS
to be a precise type and loose the two possible overload here.
from immutable-js.
After some tests, I think #1936 does fix this and is a better declaration file for me :
- it keeps the FromJS best possible type with object,
- it fallbacks to Collection<unknown, unknown>,
- if type is hard (like you case), it fallback to
any
from immutable-js.
Related Issues (20)
- createSerializableStateInvariantMiddleware for Record in React Redux TS HOT 1
- Supporting wildcards HOT 7
- Converting a Seq to a list causes RangeError (max call size exceeded) HOT 1
- 4.2.0: partition missing in flow HOT 3
- Question: Wiki article for upgrading to v4 HOT 3
- `toJS` breaks type compatibility between records with object values HOT 8
- Wrong typescript declarations for `.update()` method (continued) HOT 2
- Record with more keys should be assignable to Record with less keys if type is a subset of the first one
- ReferenceError: Immutable is not defined HOT 9
- Highlight inputs where `Set` can't maintain uniqueness HOT 4
- Flow type definition outdated, not working with last year changes HOT 1
- Urgent: Package Installation Reveals Multiple Vulnerabilities HOT 1
- Type predicate missing on isOrderedSet function type declaration
- support deno HOT 2
- immutable default import in 5.x
- version 4.3.3 breaks TS/Angular/webpack HOT 2
- Typescript: Implement `MapOf::merge `
- Extract sort function from Collection types HOT 6
- Enhancement: Custom equals HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from immutable-js.