-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
[Docs] Update all code blocks to toggle between TS and JS syntax #4112
Comments
Does the JS come out looking weird at all? |
Also, the toggle does cause the page layout to change and the scroll position to move. Any way to avoid that? Not a dealbreaker, just an annoyance. |
No, the TS compiler is set up to effectively just strip the types. For that example, the TS source is: import { createSlice, PayloadAction } from '@reduxjs/toolkit'
interface CounterState {
value: number
}
const initialState = { value: 0 } as CounterState
const counterSlice = createSlice({
name: 'counter',
initialState,
reducers: {
increment(state) {
state.value++
},
decrement(state) {
state.value--
},
incrementByAmount(state, action: PayloadAction<number>) {
state.value += action.payload
},
},
})
export const { increment, decrement, incrementByAmount } = counterSlice.actions
export default counterSlice.reducer and the JS is: import { createSlice } from '@reduxjs/toolkit'
const initialState = { value: 0 }
const counterSlice = createSlice({
name: 'counter',
initialState,
reducers: {
increment(state) {
state.value++
},
decrement(state) {
state.value--
},
incrementByAmount(state, action) {
state.value += action.payload
},
},
})
export const { increment, decrement, incrementByAmount } = counterSlice.actions
export default counterSlice.reducer |
the only page layout change I'm seeing is that the code block shrinks when you go TS->JS, because there's just fewer lines of code to show. Anything else beyond that? |
Yeah, it's just that. If it's avoidable, that would be cool, but I know it's difficult. |
I think JS/TS tab switching UI intended to be one of the solution of resolve less readability by JS/TS code amount gap. To start this, we have to be clear which way goal is. |
Hi, can we add TS version for testing docs? |
@timdorr @markerikson FYI if facebook/docusaurus#5618 gets accepted, it should address the above page layout shifting |
The RTK docs currently use Lenz Weber's https://github.com/phryneas/remark-typescript-tools plugin to let us write TS syntax in code blocks, compile away the TS syntax to plain JS, and show both versions as a tab, as seen at https://redux-toolkit.js.org/api/createSlice:
We ought to start doing the same thing for the RTK docs.
The relevant RTK docs build config is at https://github.com/reduxjs/redux-toolkit/blob/818efb9c9e46df23c891feaab869d72f2d9ecc35/website/docusaurus.config.js#L12-L53 .
We might also want to look at https://shikijs.github.io/twoslash/ , which is built by one of the TS devs. Lenz has said he'd like to investigate switching the RTK docs over to that at some point, so worth considering now.
The text was updated successfully, but these errors were encountered: