Skip to content

Instantly share code, notes, and snippets.

@alexbaumgertner
Last active May 8, 2021 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbaumgertner/10fedeaa14b6847f371127850b2d93f9 to your computer and use it in GitHub Desktop.
Save alexbaumgertner/10fedeaa14b6847f371127850b2d93f9 to your computer and use it in GitHub Desktop.
interface Page<T> {
title: string;
content: string;
lang: T;
}
function getPage<T> (
title: string,
content: string,
lang: T,
): Page<T> {
return {
title,
content,
lang,
}
}
class AppPage<T> {
constructor (
private title: string,
private content: string,
private lang: T,
) {}
public get page () {
return getPage(
this.title,
this.content,
this.lang,
)
}
}
enum lang {
ru = 'ru',
en = 'en',
}
const appPage = new AppPage(
'App',
'Hello, World!',
lang.en as const,
)
appPage.page
// WebStrom
AppPage<lang.en>.page(): Page<T>
// VSCode
AppPage<lang.en>.page: Page<lang.en>
@alexbaumgertner
Copy link
Author

WebStorm
Screenshot 2021-05-08 at 20 49 01

VS Code
Screenshot 2021-05-08 at 20 49 17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment