mirror of
https://github.com/cupcakearmy/typescript-talk.git
synced 2024-12-22 08:06:31 +00:00
better contructor and naming
This commit is contained in:
parent
18026c8e97
commit
a0768a8cd7
42
index.html
42
index.html
@ -487,25 +487,21 @@
|
||||
<section>
|
||||
<h3>Advanced Stuff</h3>
|
||||
<pre><code data-trim class="hljs">
|
||||
type RequireSome<T, K extends keyof T> = {
|
||||
[X in Exclude<keyof T, K>]?: T[X]
|
||||
} & {
|
||||
[P in K]-?: T[P]
|
||||
}
|
||||
import { NonFunctionKeys } from 'utility-types'
|
||||
|
||||
class Auto {
|
||||
wheels!: number
|
||||
doors?: number
|
||||
// ...
|
||||
|
||||
constructor(init: RequireSome<Auto, 'wheels'>) {
|
||||
constructor(init: Pick<Auto, NonFunctionKeys<Auto>>) {
|
||||
Object.assign(this, init)
|
||||
}
|
||||
}
|
||||
|
||||
const a = new Auto({
|
||||
wheels: 4,
|
||||
doors: 5,
|
||||
wheels: 4, // Required
|
||||
doors: 5, // Optional
|
||||
})
|
||||
</code></pre>
|
||||
</section>
|
||||
@ -561,7 +557,7 @@
|
||||
</code></pre>
|
||||
</section>
|
||||
<section>
|
||||
<h3>Options exclude each other</h3>
|
||||
<h3>Discriminated unions</h3>
|
||||
<pre><code data-trim class="hljs">
|
||||
type ColumnProps = {
|
||||
width: number;
|
||||
@ -787,22 +783,22 @@
|
||||
fragmentInURL: true,
|
||||
slideNumber: 'c/t',
|
||||
dependencies: [{
|
||||
src: 'https://unpkg.com/reveal.js/plugin/markdown/marked.js'
|
||||
},
|
||||
{
|
||||
src: 'https://unpkg.com/reveal.js/plugin/markdown/markdown.js'
|
||||
},
|
||||
{
|
||||
src: 'https://unpkg.com/reveal.js/plugin/notes/notes.js',
|
||||
async: true
|
||||
},
|
||||
{
|
||||
src: 'https://unpkg.com/reveal.js/plugin/highlight/highlight.js',
|
||||
async: true
|
||||
}
|
||||
src: 'https://unpkg.com/reveal.js/plugin/markdown/marked.js'
|
||||
},
|
||||
{
|
||||
src: 'https://unpkg.com/reveal.js/plugin/markdown/markdown.js'
|
||||
},
|
||||
{
|
||||
src: 'https://unpkg.com/reveal.js/plugin/notes/notes.js',
|
||||
async: true
|
||||
},
|
||||
{
|
||||
src: 'https://unpkg.com/reveal.js/plugin/highlight/highlight.js',
|
||||
async: true
|
||||
}
|
||||
]
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user