Skip to content
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

Typescript ESType definition improvements #27545

Open
wesleyolis opened this issue Oct 4, 2018 · 3 comments
Open

Typescript ESType definition improvements #27545

wesleyolis opened this issue Oct 4, 2018 · 3 comments
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@wesleyolis
Copy link

Hi,

The following types can be improved on to be more correct in the lib.es5.d.ts file.

These type improve typically deal with the cases on of the arrays items keys has subset of the other keys, in this case the results is the common subset, with mismatching fields made optional.

This requires functionality in typelevel-ts, however, that is only based on keys.
new methods should do and K in keyof T, T[K] extends S[K] ? K : never

// Improved more correctly helper method.
type ObjectOmit<T extends Record<string,any>, O extends Record<string,any>, KeyOfO keyof O> = Pick<T, {
 [K in keyof T] : K extends KeyOfO ? 
                         T[K] extends O[K] | undefined ? never : K // may need a two way extends comparison here.
                          : K
}[keyof T]

export function ObjectAssign<T extends Record<string,any>, U extends Record<string,any>>(target: T, source: U): 
ObjectOverwrite<T, U>
{
  return Object.assign(target, source);
}

export function ArrayConcat<A>(arrayA: A [] , arrayB : A []) : A[]

export function ArrayConcat<B, A extends B>(arrayA: A [], arrayB : B []) : B & Partial<ObjectOmit<A, keyof B>>[]
export function ArrayConcat<A, B extends A>(arrayA: A [], arrayB : B []) : A & Partial<ObjectOmit<B, keyof A>>[]
{
  return arrayA.concat(arrayB) as any
}


export function FilterDefined<T>(items : Array<T> | undefined) : NonNullable<T> []
{
  if (items)
    return items.filter(f => f != undefined) as NonNullable<T> [];
  else
    return []; 
}
@weswigham weswigham added Suggestion An idea for TypeScript Help Wanted You can do this Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Oct 16, 2018
@weswigham
Copy link
Member

If someone can open a PR with the suggested change (addition?) on https://github.com/Microsoft/TSJS-lib-generator we can take a look at it and decide if it'll work without breaking the community.

@saschanaz
Copy link
Contributor

If someone can open a PR with the suggested change (addition?) on https://github.com/Microsoft/TSJS-lib-generator

But ES types are not covered by that repo?

@weswigham
Copy link
Member

Ahhhh, you would be correct. I suppose here, then.

@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants