Last active
June 28, 2024 12:49
-
-
Save raphaeldealmeida/4b0b84ae082fc28b66a7b69f2647d133 to your computer and use it in GitHub Desktop.
Mithril VS Code snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Mithril snippets | |
// Paste in File > Preferences > Configure User Snippets > typescriptreact.json | |
// ref: https://code.visualstudio.com/docs/editor/userdefinedsnippets | |
"Mithril component": { | |
"prefix": ["mcomp"], | |
"body": [ | |
"import m from \"mithril\"", | |
"", | |
"interface T${1:MyComponent}Props {}", | |
"const $1: m.ClosureComponent<T$1Props> = () => {", | |
"", | |
" return {", | |
" view: () => {", | |
" return <>", | |
" $1", | |
" </>", | |
" }", | |
" }", | |
"}", | |
"", | |
"export default $1", | |
], | |
"description": "A component Mithril" | |
} | |
} |
@nandoflorestan Notes accepted.
The prefix T implies that it is a Type, the most appropriate thing here is to use the prefix I for Interfaces. @
User code doesn't care whether it's an interface or a type, this is an implementation detail due to the evolution of the TypeScript language. It's better to keep a T prefix for everything, then you can switch the implementation between types and interfaces freely, without changing user code.
Ok.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice.
TS documentation suggests preferring interface to type except when you need features specific to type.
I don't see a reason to leave a blank line after the line with the component name.