Advanced Stuff
- 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
})
@@ -561,7 +557,7 @@
- Options exclude each other
+ Discriminated unions
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
+ }
]
});