theara
April 17, 2020, 3:44am
1
Now I tried to use Meteor + Typescript
:
// server/services.ts (Incorrect function to return)
export default function hello(msg: string): number {
return msg
}
--------------------------
// server/methods.ts
import hello from './services'
Meteor.methods({
hello(msg) {
return hello(msg);
}
});
-------------
// client/...
Meteor.call("hello", "Rabbit", (err, res) => {
console.log(res); // Work fine
});
I still work fine, Pl help me!
My tsconfig.json
{
"compilerOptions": {
/* Basic Options */
"target": "es2018",
"module": "esNext",
"lib": ["esnext", "dom"],
"allowJs": true,
"checkJs": false,
"jsx": "preserve",
"incremental": true,
"noEmit": true,
/* Strict Type-Checking Options */
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
/* Additional Checks */
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": false,
/* Module Resolution Options */
"baseUrl": ".",
"paths": {
/* Support absolute /imports/* with a leading '/' */
"/*": ["*"]
},
"moduleResolution": "node",
"resolveJsonModule": true,
"types": ["node", "mocha"],
"esModuleInterop": true,
"preserveSymlinks": true
},
"exclude": [
"./.meteor/**",
"./packages/**"
]
}
theara
April 19, 2020, 2:40am
2
Or Typescript
only check error on IDE (VSCode)???
But still work fine when running!!!
Yeah, Meteor doesn’t do any type checking, even with the typescript
package.
The idea being that you can run typescript on it’s own for checking, or as a pre-commit hook and use IDE features for the rest.
VSCode has such good typescript support that I hardly notice that Meteor isn’t doing any checking
1 Like
theara
April 20, 2020, 5:04am
4
@coagmano , thanks for your reply.
It mean that VSCode is alter all error type typescript
.
But still work while we run meteor.
theara
April 20, 2020, 5:07am
5
How to config to check debug when runing, if typescript is error???
// Example
let data: number
data = "Hello"
Would like to show error when
meteor run
I would love to have type checking in Meteor as well, are there any plans for it to be added to the typescript package?
Also, does anyone have suggestions for how to set up the pre-commit hook?
1 Like
I use husky for hooks, with lint-staged like this (in package.json):
"husky": {
"hooks": {
"pre-commit": "tsc --noEmit && npm run lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint",
"prettier --write"
],
"*.styl": [
"stylus-supremacy format --options ./.stylus-supremacy.json --replace"
]
},
EDIT: Realised I had a bug, so moved tsc --noEmit
to the hook, so it runs with the whole project context (using tsconfig) rather than on each changed file individually
4 Likes
@coagmano , thanks for your advice.
But I am not clear about this.
Could you share any example Meteor Type
Sample App?
@theara , I was specifically answering this question:
Which runs tsc --noEmit
to typecheck the project before a commit
2 Likes
I have been using this precommit hook - it is great! Thanks for the tip!
weissi8
October 31, 2020, 8:48pm
11
Using just typescript only is not the solution. If someone hacks my client and inserts an object instead of the string it is not really save if I want to be 100 % sure that there is no wrong type in my database
That a case for Sherlock Holmes SimpleSchema
, usually, or for check
. Methods and subscriptions definitely need to be guarded with strong parameter type checking.
2 Likes