-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experimental typescript support #19842
Experimental typescript support #19842
Conversation
03562c6
to
a64c911
Compare
a64c911
to
940a4c9
Compare
This is interesting like mypy is :-) Some general note/thoughts: I would love to have some IDE integration working with typescript as I am silly and sometimes type The current approach of the PR requires files to be whitelisted to be linted and to be typescript, this seems suboptimal. I would love to already start using the types available to use so what I did was:
Ok that does nothing, because we allowlist files, so I added Some really interesting things: This is not typed, but already shows a "bug"
PattternFly is typescript so we get interesting errors:
when something is half typed or is imported without typing typescript lang server is not happy which is a big blocker :(
I would need to do a bit more investigation, but it would be neat if we can maybe start whitelisting directories for typescript, the import issue seems to mostly block that but maybe there is a way around it? |
@@ -262,10 +266,10 @@ export function useObject(create, destroy, deps, comps) { | |||
|
|||
destroy_ref.current = destroy; | |||
useEffect(() => { | |||
return () => destroy_ref.current?.(ref.current); | |||
return () => { destroy_ref.current?.(ref.current!) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the bang needed for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The destroy function takes a non-null pointer, but the current value is null-typed. The !
is an assertion which means "I promise this isn't null".
6c7dc8f
to
7a3b436
Compare
Here's a few changes after feedback (as well as fixing the problems identified above). The main changes:
Now, running |
It hasn't been spoken out loud yet, so I'll say it now: the eventual goal is to have |
I think the team agrees on this. See this comment of @martinpitt and btw someone did attempt some type hints in the past maybe it's usable? |
From our meeting:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks harmless enough to me.
Let's set this aside for now. cockpit-project/cockpit-files#211 is where we're going to do this for the time being, but we can easily come back to this PR later. |
Add the typescript compiler to our devel dependencies and run it from `test/static-code`. We add an initial cockpit.d.ts and a tsconfig.json which will get `tsc` to report errors against any `.ts` or `.tsx` files.
Add some type annotations to make it compile with strict mode enabled.
* Our main build is via `esbuild` which can handle `.ts`, but doesn't do any | ||
* checking on its own. To typecheck, run `tsc`. | ||
* | ||
* Extended JSON — comments and trailing commas are good here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, does that not support something more expressive, like yaml..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of this is still under debate, but as it's completely on the "lint" side for now, it remains fungible. So I'm fine with landing that, and changing it as we need it -- at least we get the bits into node_modules/ for easy experimentation.
Thanks!
], | ||
"noEmit": true, // we only use `tsc` for type checking | ||
"skipLibCheck": true, // don't check node_modules | ||
"strict": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose that's still under debate? It wasn't at all clear to me after the meeting whether we should turn this on or off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the conclusion was that we want strict mode for .ts and a non-strict mode for .js coming along in some future PR.
@@ -262,10 +273,10 @@ export function useObject(create, destroy, deps, comps) { | |||
|
|||
destroy_ref.current = destroy; | |||
useEffect(() => { | |||
return () => destroy_ref.current?.(ref.current); | |||
return () => { destroy_ref.current?.(ref.current!) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it need to be wrapped into {}
now? Does the current() call return something non-void?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the !
somehow caused syntactic problems if it wasn't in a block. I honestly don't remember: it was a long time ago.
3ec539a
into
cockpit-project:main
I want to use typescript in an upcoming test page in the playground. Let's lay some foundations.
I ported
hooks.js
to typescript because:I didn't port
cockpit.js
because:In any case, if everything is working correctly, this shouldn't actually change anything.
For the record:
The
@types
includes are fairly harmless, but I'm a bit more worried about adding typescript itself. That's a ~7% increase in the size of ournode_modules
. We could alternatively use the version of typescript available in Fedora and make sure to install it somewhere (tasks container, dev depenency during package builds, whatever) to make suretest/static-code
can run it in CI.todo
esbuild transparently supports .ts, but make sure this works with a webpack project, too (cockpit-composer?)we don't care about webpack anymore