Skip to content

Write a Webpack loader to support check using TypeScript interface #1

@hanlindev

Description

@hanlindev

TypeScript interface are stripped away when being transpiled. This is a big waste of resource because the interface-validator's syntax is adopted from TypeScript's interface syntax.
Write a Webpack loader to transform some special syntax to using interface-validator. Here are a few options:

  • Detect instanceof against interfaces. For example
interface Product {
  name: string;
  price?: {
    value: number;
    currency: string;
  }
}
obj instanceof Product;

Will be transformed to

interfaceValidator.validate(obj, {
  name: 'string',
  'price?': {
    value: 'number',
    currency: 'string'
  }
});

I don't know how to make tsc run pre-compile hooks yet. If that is achievable, I can write a separate module for pre-compile processing first. That'll make this usable outside Webpack.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions