Coder Social home page Coder Social logo

Comments (11)

fregante avatar fregante commented on September 26, 2024 1

If we move the types here, it may be worth it listing all the element types inside IntrinsicElements and that might allow us to type them correctly. It's not like new elements pop out every day so it as long as we can at least partially reuse React's we're good

from dom-chef.

nickytonline avatar nickytonline commented on September 26, 2024 1

It appears to be correct based on the spec here, https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td

colspan
This attribute contains a non-negative integer value that indicates for how
many columns the cell extends. Its default value is 1. Values higher than 1000
will be considered as incorrect and will be set to the default value (1).

But in practice colspan="5" has always worked in HTML.

from dom-chef.

fregante avatar fregante commented on September 26, 2024 1

v5 is live thanks to @TheRealSyler!

from dom-chef.

nickytonline avatar nickytonline commented on September 26, 2024

Pulled this out of globals.d.ts from Refined GitHub to leave as a TODO for this issue.

// TODO: add support for `class` in JSX
// The following code works if it's inside the file with JSX, but here it breaks all JSX definitions.
// The `namespace JSX`  merges fine because in react's types it's `global`, but `namespace React` isn't
//
// import React from 'dom-chef';
// declare global {
// 	namespace React {
// 		interface DOMAttributes<T> {
// 			class?: string;
// 		}
// 	}
// }

from dom-chef.

fregante avatar fregante commented on September 26, 2024

Also weird edge case to fix, either here or in @types/react:

<td colspan="5">
// TS2322: Type '{ children: Element; colspan: string; }' is not assignable to type 'DetailedHTMLProps<TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>'.
//   Property 'colspan' does not exist on type 'DetailedHTMLProps<TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>'.

<td colSpan="5">
// TS2322: Type 'string' is not assignable to type 'number | undefined'.

<td colSpan={5}>
// fine...

Workaround: sindresorhus/hide-files-on-github@6bd22ba

declare namespace JSX {
	interface Element extends SVGElement, HTMLElement, DocumentFragment {}
	type TdIntrinsicElement = IntrinsicElements['td'];
	interface IntrinsicElements {
		'td': TdIntrinsicElement & {colspan?: string};
	}
}

from dom-chef.

fregante avatar fregante commented on September 26, 2024

Indeed, then maybe colSpan={5} isn't too bad. It just looks weird but technically correct.

from dom-chef.

jtbandes avatar jtbandes commented on September 26, 2024

I recently tried to combine usage of dom-chef and React in the same project (some files would use dom-chef, and some would use React). I have custom JSX types for dom-chef (see #54 (comment)), but when I install @types/react it's automatically included and it seems like the TS compiler doesn't allow specifying which JSX types will be used — I get "duplicate identifier" errors in my custom JSX.d.ts.

However, I noticed that refined-github somehow uses @types/react and modifies the types here: https://github.com/sindresorhus/refined-github/blob/0f0fe746be058510455be1bb3ae1c1d78fea6154/source/globals.d.ts#L47-L65

Can you explain how that works without introducing conflicts like "duplicate identifier"?

from dom-chef.

fregante avatar fregante commented on September 26, 2024

It’s hard to understand what the problem is without seeing your JSX.d.ts

At some point we’ll merge #62 and that should make it easier

from dom-chef.

jtbandes avatar jtbandes commented on September 26, 2024

Thanks, #62 looks great. When that is merged, will it be possible to use dom-chef and React in the same repo (different files though)?

My question above was more about how the JSX types override in refined-github works. I tried copying this into my project and I got "duplicate identifier" errors, just wanted to know if I was missing something. I couldn't find any TypeScript docs that explain how it works when you have multiple declare globals overriding each other.

from dom-chef.

fregante avatar fregante commented on September 26, 2024

I think you can only use that in your global.d.ts making sure it's not read as a "module", i.e. it can't have any import/export

from dom-chef.

fregante avatar fregante commented on September 26, 2024

I think this will be closed by #62. Review that PR before it's merged as v5

from dom-chef.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.