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

Add a new type PublicOf #31891

Open
5 tasks done
sroucheray opened this issue Jun 13, 2019 · 3 comments
Open
5 tasks done

Add a new type PublicOf #31891

sroucheray opened this issue Jun 13, 2019 · 3 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@sroucheray
Copy link
Contributor

Suggestion

Add the PublicOf type suggested in this issue's comment by @DanielRosenwasser

Use Cases

Implement a class public properties/methods without the need to implement private/protected ones.

Examples

// type to add
type PublicOf<T> = {
    [P in keyof T]: T[P]
}
// use case
class C {
    private foo();

    public bar();
}

// No need to implement private method foo !
class D implements PublicOf<C> {
    public bar() {}
}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@dragomirtitian
Copy link
Contributor

This seems to me a marginal improvement over Pick<C, keyof C>

declare class C {
    private foo(): void

    public bar(): void
}

// No need to implement private method foo !
class D implements Pick<C, keyof C> {
    public bar() { }
}

@sroucheray
Copy link
Contributor Author

Good point, alternate implementation:

type PublicOf<T> = Pick<T, keyof T>;

@DanielRosenwasser DanielRosenwasser added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jun 13, 2019
@sroucheray
Copy link
Contributor Author

I'm trying a contribution, I'm not sure that my pull request #31970 is valid but I'm still trying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants