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
Non-nullable types support for TypeScript 2.0 #914
Comments
Something like this? #919 is a start, but full non-nullable types support needs more work I'm afraid. |
#919 was merged, but this only fixes the closure parameters. The remaining issue is with the return types: listOfNumbers.get(5) // returns 5, should return 5 | undefined What work is involved to get this done? Is it simply a case of updating the type definitions? |
This might get tricky because const array: number[] = [];
array[5000] = 5;
const a = array[0]; // a is a `number`, not `number | undefined` !!!
const b = List().toArray();
// **EDIT**: this is not actually accurate for JavaScript:
// b.forEach(v => { /* v has `number` type but can have `undefined` value! */ } );
// b.map(v => { /* v has `number` type but can have `undefined` value! */ } );
// ... So one has to decide should Immutable.js mimic this behavior or should it have more type safety? Or should we instead change all mutation methods which may potentially introduce undefined values to return List<T | undefined>? Like function of<T>(...values: T[]): List<T>;
function List<T>(): List<T>;
function List<T>(array: Array<T>): List<T | undefined>;
interface List<T> extends Collection.Indexed<T> {
// ...
push(...values: T[]): List<T>; // push can't add undefined values, so we keep List<T> type
set(index: number, value: T): List<T | undefined>; // can't guarantee that new list won't have undefined values
setSize(size: number): List<T | undefined>; // can't guarantee that new list won't have undefined values
} I don't know... EDIT: I wasn't quite accurate: JavaScript actually does not iterate over undefined values if one does |
Interestingly, TypeScript's built-in signature for ES6 |
All of this looks quite messy to me. For example, forEach of Javascript array and forEach of Immutable.js List have different semantics: const array: number[] = [];
array[3] = 5;
array.forEach(v => console.log(v));
// Output:
// 5 vs const list = List<number>().set(3, 5);
list.forEach(v => console.log(v));
// Output:
// undefined
// undefined
// undefined
// 5 I don't see a particularly good way to make it both null-safe and not annoying to use in real life. Any ideas? |
Another issue: Immutable.js is using .d.ts file to build documentation by using custom TypeScript syntax processor which is based on TypeScript version 1.3 embedded into the source tree (https://github.com/facebook/immutable-js/blob/master/pages/third_party/typescript/package.json). Obviously it breaks down when I add TL;DR: you can't just upgrade typings with union types, non-nulls, tuple types, |
Looks like a lot of this is already in git and not released, noticed thanks to #1034 |
New type definitions are almost done, and will be released soon! |
@leebyron What does "soon" mean in this context? I'm getting TS compiler errors because the definition for predicates have nullable parameters, when in reality they don't. If a release is coming in a day or two, I'll wait. If not, I'll have to figure out a way to manually bring the updated definitions into my project. |
Since a new version of TypeScript with --strictNullCheck will be released soon it would be cool to have support for this in Immutable.js typings.
microsoft/TypeScript#7140
The text was updated successfully, but these errors were encountered: