Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Jul 11, 2017

For example, we can now map over readonly arrays.

@ghost ghost requested a review from weswigham July 11, 2017 16:03
}
else {
result.push(v);
result.push(v as T);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this cast here because the isArray helper doesn't guard for readonly array types? Can it not be overloaded to do so?

Copy link
Author

@ghost ghost Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I thought changing isArray would break things. But it seems to work fine to return x is ReadonlyArray<any>.


function getAccessibleSymbolChainFromSymbolTableWorker(symbols: SymbolTable, visitedSymbolTables: SymbolTable[]): Symbol[] {
if (contains(visitedSymbolTables, symbols)) {
if (contains<SymbolTable>(visitedSymbolTables, symbols)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need an explicit type argument now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are problems with inferring type arguments -- when you get Foo[] and expect ReadonlyArray<T>, we have trouble inferring that T = Foo.

* Compacts an array, removing any falsey elements.
*/
export function compact<T>(array: T[]): T[];
export function compact<T>(array: ReadonlyArray<T>): ReadonlyArray<T>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this overload order correct? Won't we just always pick the top one, since a ReadonlyArray will be compatible with it (so we'll never go down the list)? (Same comment on singleOrMany, concatenate, sameFlatMap, sameMap, and filter)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more-specific overload should go first -- T[] is more specific than ReadonlyArray since it contains everything ReadonlyArray has, plus mutators.

* Without these methods, only completions for ambient modules will be provided.
*/
readDirectory?(path: string, extensions?: string[], exclude?: string[], include?: string[], depth?: number): string[];
readDirectory?(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok to change this? Does this count as a breaking change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, but code should never have modified the extensions array anyway.

@ghost ghost force-pushed the readonlyarray2 branch from 0884053 to 52ce0aa Compare July 11, 2017 20:38
@ghost ghost merged commit 08030c7 into master Jul 12, 2017
@ghost ghost deleted the readonlyarray2 branch July 12, 2017 00:39
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants