- Jun 2024
-
www.second.dev www.second.dev
- Oct 2023
-
www.typescripttutorial.net www.typescripttutorial.net
-
- Sep 2023
-
mistlog.medium.com mistlog.medium.com
-
mistlog.github.io mistlog.github.io
-
johtela.github.io johtela.github.io
-
type-level-typescript.com type-level-typescript.com
-
- Aug 2023
-
developer.mozilla.org developer.mozilla.org
-
-
Add aliases to
vite.config.ts
```js import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import path from 'path';
// https://vitejs.dev/config/ export default defineConfig({ resolve: { alias: { '@': path.resolve(__dirname, './src'), '@assets': path.resolve(__dirname, './src/assets'), '@components': path.resolve(__dirname, './src/components'), }, }, plugins: [react()] }) ```
Add aliases to
tsconfig.json
```js { "compilerOptions": { // ... your other compiler options "baseUrl": ".", "paths": { "@/": ["src/"], "@components/": ["src/components/"], "@assets/": ["src/assets/"] }, }, "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] } ````
Use alias
js import image from `@assets/image.png`
Tags
Annotators
URL
-
-
svelte.dev svelte.dev
Tags
Annotators
URL
-
- Jul 2023
- Jun 2023
-
betterprogramming.pub betterprogramming.pub
-
www.totaltypescript.com www.totaltypescript.com
Tags
Annotators
URL
-
-
www.typescriptlang.org www.typescriptlang.org
-
- May 2023
-
github.com github.com
-
Workers Types Generator
-
-
blog.logrocket.com blog.logrocket.com
Tags
Annotators
URL
-
-
wojciechkrysiak.medium.com wojciechkrysiak.medium.com
-
www.prisma.io www.prisma.io
Tags
Annotators
URL
-
-
www.typescriptlang.org www.typescriptlang.org
-
www.typescriptlang.org www.typescriptlang.org
Tags
Annotators
URL
-
-
www.typescriptlang.org www.typescriptlang.org
-
With TypeScript 3.7, TypeScript added support for generating .d.ts files from JavaScript using JSDoc syntax. This set up means you can own the editor experience of TypeScript-powered editors without porting your project to TypeScript, or having to maintain .d.ts files in your codebase.
npx -p typescript tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir types
-
-
www.typescriptlang.org www.typescriptlang.org
Tags
Annotators
URL
-
-
remix.run remix.run
Tags
Annotators
URL
-
-
www.typescriptlang.org www.typescriptlang.org
-
microsoft.github.io microsoft.github.io
-
github.com github.com
-
js /** * This component is just a Box with border. * It serves as an example of how you can incorporate * components together. * * Component also has slots, methods and events. * * @component * @example <caption>Basic usage just with the default slot</caption> * <Box> * I am inside a slot * </Box> * * @example <caption>Using second component inside</caption> * <Box> * <ProgressBar :spent="spent" :remaining="50"></ProgressBar> * </Box> * * @example <caption>Example of passing an entire component in a preview</caption> * { * template: `<Box> * <ProgressBar :spent="spent" :remaining="50"></ProgressBar> * <ProgressBar :spent="50" :remaining="50" style="margin-top: 20px"></ProgressBar> * </Box>`, * data: function() { * return {spent: 223}; * } * } */ export default { name: "Box", props: { /** * This will be in the header */ title: { type: String, default: "My box" } }, methods: { /** * Also, you can describe methods for each component * the same as you would do this in regular @jsdoc * documented file * * @param {string} prop1 some example property * @param {string} prop2 other property */ exampleMethod(prop1, prop2) { // method body // The method could even throw an event /** * This event could be thrown by component in case * of some kind of unexpected behaviour. * * @category API * @event unexpectedEvent */ this.$emit('unexpecteEvent') } } }
Tags
Annotators
URL
-
-
-
```ts
/* * Initiates a connection to the selected port. / async function connectToServer(): Promise<void> { hostInput.disabled = true; portInput.disabled = true; connectButton.textContent = 'Connecting...'; connectButton.disabled = true;
try { socket = new TCPSocket(hostInput.value, parseInt(portInput.value)); connection = await socket.opened; term.writeln('<CONNECTED>'); connectButton.textContent = 'Disconnect'; connectButton.disabled = false; } catch (e) { console.error(e); term.writeln(
<ERROR: ${e.message}>
); markDisconnected(); return; }try { reader = connection?.readable.getReader(); for (;;) { const {value, done} = await reader.read(); if (value) { await new Promise<void>((resolve) => { term.write(value, resolve); }); } if (done) { break; } } reader.releaseLock(); reader = undefined; } catch (e) { console.error(e); term.writeln(
<ERROR: ${e.message}>
); }markDisconnected(); }
/* * Closes the currently active connection. / async function disconnectFromServer(): Promise<void> { // Canceling |reader| will close the connection and cause the read loop in // connectToServer() to exit when read() returns with done set to true. if (reader) { await reader.cancel(); } } ```
-
- Apr 2023
-
desislav.dev desislav.dev
-
- Mar 2023
-
simplewebauthn.dev simplewebauthn.dev
Tags
Annotators
URL
-
-
www.typescriptlang.org www.typescriptlang.org
Tags
Annotators
URL
-
-
vanilla-extract.style vanilla-extract.style
-
-
sergiodxa.com sergiodxa.com
-
Put that TS code in a file your app imports, for example, in remix.env.d.ts, and now the type of name will be the expected one.
ts declare module "@remix-run/server-runtime" { export interface AppLoadContext { name: string; } }
-
-
fjolt.com fjolt.com
-
If we want to create an immutable, read only Tuple in Typescript, we can use the readonly keyword when defining our Tuple.
ts const myArray:readonly[number, string] = [10, 'test'];
-
Unlike the tuple type in vanilla Javascript, Typescript Tuples by default are mutable - so they can be changed. As such, we can update a Tuple by simply referring to the element we want to update, and redefining it, assuming it isn't a constant:
Mutating a Typescript Tuple
```ts let myTuple:[ string, number ] = [ "some", 15 ]
myTuple[1] = 20; ```
-
We can also define an array of Tuples in Typescript. This is done by adding [] to the end of our Tuple type definition:
ts let myTuple:[ string, number ][] = [ [ "some", 15 ], [ "other", 20 ], [ "tuple", 50 ] ];
-
ts const myTuple:[ string, number ] = [ "some", 15 ]
Tags
Annotators
URL
-
-
artsy.github.io artsy.github.io
-
Now we have autocomplete and typechecking.
```ts type ColorDSValue = "black100" | "black80" | "blue100" | "red150" // | etc type ColorOtherString = string & {}
type Color = ColorDSValue | ColorOtherString ```
-
This is so so useful for types or props where you want the general type for support (string), but you also want the specific type for autocomplete ("black100"). It made my whole week when I figured that out and made that color type.
-
This weird-looking intersection of string & {} makes it so that the specific strings "hello" and "world" are distinguished from string as a whole type.
ts const wow: ("hello" | "world") | (string & {}) // `wow` is of type `"hello"` or `"world"` or `string`.
Tags
Annotators
URL
-
-
andreitopli.medium.com andreitopli.medium.com
- Feb 2023
-
webpack.js.org webpack.js.org
-
-
react-typescript-cheatsheet.netlify.app react-typescript-cheatsheet.netlify.app
Tags
Annotators
URL
-
-
www.typescriptlang.org www.typescriptlang.org
Tags
Annotators
URL
-
-
remix.run remix.run
Tags
Annotators
URL
-
-
www.typescriptlang.org www.typescriptlang.org
Tags
Annotators
URL
-
- Jan 2023
-
www.typescriptlang.org www.typescriptlang.org
-
- Dec 2022
-
-
- Nov 2022
-
www.epicweb.dev www.epicweb.dev
Tags
Annotators
URL
-
- Aug 2022
-
rmolinamir.github.io rmolinamir.github.io
Tags
Annotators
URL
-
-
www.tektutorialshub.com www.tektutorialshub.com
-
The unary plus operator (+) precedes its operand and converts it into a number. If it fails to convert the operand into a number, then it returns NaN. The unary (-) operator converts the operand into a number and negates it.
an alternative to !!, in order to convert null, empty strings, boolean values into 0 or 1.
-
- May 2022
-
usehooks-ts.com usehooks-ts.com
-
- Apr 2022
- Feb 2022
-
mariusschulz.com mariusschulz.com
Tags
Annotators
URL
-
-
zhenghao.io zhenghao.ioZhenghao1
-
- Jan 2022
-
www.executeprogram.com www.executeprogram.com
Tags
Annotators
URL
-
- Dec 2021
-
nicotsou.com nicotsou.com
-
-
morioh.com morioh.com
-
-
www.typescriptlang.org www.typescriptlang.org
-
medium.com medium.com
-
The correct way to handle TypeScript functional destructuring is to define an interface and reference the interface after the destructure. TypeScript is then able to understand that the function takes an object argument that is of the shape of the Person interface and destructuring occurs as you would expect it to in ES6.
// a 'Person' object requires 'first' and 'last' // properties whose values are strings interface Person { first: string; last: string; } // This defines that the first functional argument // must be an Array of 'Person' objects, then destructs // the first person's first and last name properties const helloFirstPerson = ([{ first, last }]: Person[]) => `Hello ${first} ${last}!`; const people = [ { first: 'John', last: 'Doe' }, { first: 'Jane', last: 'Smith' } ]; // outputs "Hello John Doe!" helloFirstPerson(people); /* --------- Example of a Type Error ----------- */ // This creates an array argument that will be invalid for // the helloFirstPerson() function, because there are no 'last' // props on the 'people' objects const badArgs = [{ first: 'John' }, { first: 'Jane' } ]; // Type Error! // Property 'last' is missing in type '{ first: string; }' helloFirstPerson(badArgs);
-
- Nov 2021
-
www.tensorflow.org www.tensorflow.org
-
You'll use a (70%, 20%, 10%) split for the training, validation, and test sets. Note the data is not being randomly shuffled before splitting. This is for two reasons: It ensures that chopping the data into windows of consecutive samples is still possible. It ensures that the validation/test results are more realistic, being evaluated on the data collected after the model was trained.
Train, Validation, Test: 0.7, 0.2, 0.1
-
-
-
Check whether a value is defined (non-nullable), meaning it is neither `null` or `undefined`. This can be useful as a type guard, as for example, `[1, null].filter(Boolean)` does not always type-guard correctly.
-
-
-
import {isDefined} from 'ts-extras'; [1, null, 2, undefined].filter(isDefined); //=> [1, 2]
Tags
Annotators
URL
-
- May 2020
-
www.educative.io www.educative.io
-
const Hello: React.FC<Props> = ({ who }) => ( <p>Hello, {who}</p>);
最简单的 FC props定义方式
-
-
psyarxiv.com psyarxiv.com
-
Mataix-Cols, D., Ringberg, H., & de la Cruz, L. F. (2020, May 5). Perceived worsening of tics in adult patients with Tourette syndrome after the COVID-19 outbreak. https://doi.org/10.31234/osf.io/vr8km
-
- Nov 2019
-
Tags
Annotators
URL
-
- Oct 2019
-
github.com github.com
- Sep 2019
-
spin.atomicobject.com spin.atomicobject.com
-
ts-node enables you to execute TypeScript directly, just as you might execute JavaScript code using Node.
-
- Nov 2018
-
www.sitepen.com www.sitepen.com
- Oct 2018
-
scotch.io scotch.io
-
-
-
blog.programster.org blog.programster.org
-
boilerplate
-
-
-
- Sep 2018
-
github.com github.com
Tags
Annotators
URL
-