-
Notifications
You must be signed in to change notification settings - Fork 2
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
Implement as TypeScript compiler transform #5
Comments
Turns out The way the first proof-of-concept was written is incredibly wasteful (running the typescript compiler twice) so I will definitely be rewriting this as a transformer and documenting how to use it with |
From looking at https://github.com/Igorbek/typescript-plugin-styled-components, the same is also true of |
Further thoughts on this:
Given the above, it doesn't make sense to sink a lot of effort into this project. I do like the idea of generating runtime validation code from static types, but I think it makes more sense to decouple this from the react prop-types infrastructure and require explicit validations. E.g. import * as React from 'react'
import validate from 'ts-validate/validate' // a "marker" function, calls will be replaced by the transform
interface Props {
foo: string
}
export default function MyComponent(props: Props) {
validate(props) // compiler transform replaces this call with validation code generated from `Props`
return <span>{props.foo}</span>
} The
(I'm fairly certain many minifiers will actually remove the function call entirely). |
The TypeScript compiler API supports transforms for a while now. It should be possible to implement the main functionality independent of webpack, and then expose it as a compiler transform as well as a webpack loader.
Keep an eye on microsoft/TypeScript#14419 to see if a common approach to using typescript with compiler transforms comes about.
The text was updated successfully, but these errors were encountered: