Considere el siguiente código de prueba:
import { isHtmlLinkDescriptor } from '@remix-run/react/links' import invariant from 'tiny-invariant' import { links } from '~/root' it('should return a rel=stylesheet', () => { const response = links() invariant(isHtmlLinkDescriptor(response[0])) expect(response[0].rel).toBe('stylesheet') })y la implementación:
import { LinksFunction } from 'remix' import tailwindProdUrl from '~/styles/tailwind.css' export const links: LinksFunction = () => { const href = process.env.NODE_ENV !== 'production' ? './tailwind.css' : tailwindProdUrl return [{ rel: 'stylesheet', href }] } Donde LinksFunction se define aquí y aquí .
¿Por qué ESLint se queja de "Asignación insegura de any valor". y "Llamada no segura de any valor escrito". en la línea de abajo?
const response = links()Tiene una importación incorrecta en el segundo fragmento. Debería ser:
import { LinksFunction } from '@remix-run/server-runtime';o también, si está trabajando con TypeScript 3.8 o posterior:
import type { LinksFunction } from '@remix-run/server-runtime'; El hecho de que LinksFunction solo se use como un tipo en el código que está mostrando significa que el compilador de TypeScript aún podría compilar sus módulos bajo ciertas circunstancias, a pesar de las definiciones de tipo que faltan.