Migration Guide
Migrating from @typescript/twoslash
.
Consider twoslash
as the successor of @typescript/twoslash
that maintained and driven by the community. It has been rewritten to provide better performance and more flexible APIs.
Breaking Changes
Breaking changes from @typescript/twoslash
:
- The returned items have different signatures, and different types of the items (
staticQuickInfo
,queries
,errors
,tags
) are now unified into a single arraynodes
. Learn more at the Information Nodes section. - Main entry point
import {} from "twoslash"
dependent ontypescript
package, while a new sub-entryimport {} from "twoslash/core"
is dependency-free and requires providing your own TypeScript instance. defaultOptions
is renamed tohandbookOptions
.defaultCompilerOptions
is renamed tocompilerOptions
.- The default
compilerOptions
is set totarget: "esnext"
instead oftarget: "es5"
, learn more. playgroundURL
is removed
Compatibility Layer
To make it easier to migrate from @typescript/twoslash
, we provided a backward compatibility layer that allows you to use the old interface with the new implementation.
ts
import { twoslasherLegacy } from 'twoslash'
const result = twoslasherLegacy('import { ref } from "vue"', 'ts')
console.log(result.staticQuickInfos) // the old interface
You can also compose it yourself by only converting the return value:
ts
import { convertLegacyReturn, twoslasher } from 'twoslash'
const result = twoslasher('import { ref } from "vue"', 'ts') // new interface
const legacy = convertLegacyReturn(result) // <--
console.log(legacy.staticQuickInfos) // the old interface
Playground URL
Playground URL is removed from the result as for integration usage it's often redundant. If needed, you can calculate it yourself by the following snippet:
ts
import lzString from 'lz-string'
const zipped = lzString.compressToEncodedURIComponent(code)
const playgroundURL = `https://www.typescriptlang.org/play/#code/${zipped}`
ts
declare const code: string
// ---cut---
import lzString from 'lz-string'
const zipped = lzString.compressToEncodedURIComponent(code)
const playgroundURL = `https://www.typescriptlang.org/play/#code/${zipped}`