Coder Social home page Coder Social logo

ts-auto-guard's People

Contributors

aneilbaboo avatar beyer-in-tech avatar cameron-brown-future avatar cauthmann avatar chomosuke avatar chooban avatar chrisczach avatar dcsunset avatar dependabot[bot] avatar download13 avatar flixcheck avatar fthdgn avatar gh-action-bump-version avatar greenkeeper[bot] avatar hyddan avatar ldmgn avatar mastert avatar msa-itsonix avatar nhayashida avatar ntzm avatar pure-zero avatar rhys-vdw avatar ritave avatar sam-mfb avatar schmop avatar snyk-bot avatar tamiroh avatar tylerferrara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ts-auto-guard's Issues

Upgrade to ts-morph.

I was getting some compilation errors with TypeScript 3.5.1 before I updated ts-simple-ast (ts-morph) version. Should it be done here perhaps?

Cannot install

Maybe this is just me but no matter what I do, I can't install the latest version of this package. npm install obviously won't work because the latest version is not published, but doing npm install with references to git repo usually works like a charm. I must've spent a couple hours on this and am completely baffled. Any ideas?

Bug: TypeError: realpath is not a function

running ts-auto-guard in cmdlet produces the following error:

(node:11252) UnhandledPromiseRejectionWarning: TypeError: realpath is not a function
    at visitDirectory (C:\Users\admin\AppData\Roaming\npm\node_modules\ts-auto-guard\node_modules\typescript\lib\typescript.js:17838:45)
    at Object.matchFiles (C:\Users\admin\AppData\Roaming\npm\node_modules\ts-auto-guard\node_modules\typescript\lib\typescript.js:17834:13)
    at Object.matchFiles (C:\Users\admin\AppData\Roaming\npm\node_modules\ts-auto-guard\node_modules\ts-simple-ast\dist\typescript\tsInternal.js:7:35)
    at Object.readDirectory (C:\Users\admin\AppData\Roaming\npm\node_modules\ts-auto-guard\node_modules\ts-simple-ast\dist\utils\compiler\readDirectory.js:16:27)
    at Object.readDirectory (C:\Users\admin\AppData\Roaming\npm\node_modules\ts-auto-guard\node_modules\ts-simple-ast\dist\utils\tsconfig\getTsParseConfigHost.js:11:37)
    at getFileNamesFromConfigSpecs (C:\Users\admin\AppData\Roaming\npm\node_modules\ts-auto-guard\node_modules\typescript\lib\typescript.js:28531:40)
    at matchFileNames (C:\Users\admin\AppData\Roaming\npm\node_modules\ts-auto-guard\node_modules\typescript\lib\typescript.js:28451:16)
    at getFileNames (C:\Users\admin\AppData\Roaming\npm\node_modules\ts-auto-guard\node_modules\typescript\lib\typescript.js:28000:26)
    at parseJsonConfigFileContentWorker (C:\Users\admin\AppData\Roaming\npm\node_modules\ts-auto-guard\node_modules\typescript\lib\typescript.js:27932:18)
    at Object.parseJsonConfigFileContent (C:\Users\admin\AppData\Roaming\npm\node_modules\ts-auto-guard\node_modules\typescript\lib\typescript.js:27879:16)

node version v10.15.3 on windows.

An in-range update of prettier is breaking the build 🚨

The devDependency prettier was updated from 1.15.2 to 1.15.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for 1.15.3

🔗 Changelog

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Consider using ts-generator to simplify implementation

Hey!

I just stumbled upon your project, great idea! I worked on some code generation tools for typescript in the past and I realized that a lot of logic can be extracted to another tool: things like globbing files, watching, prettifying generated code etc. I have work in progress version here: https://github.com/krzkaczor/ts-generator

Would you consider switching to ts-generator in the future? Currently, I work on migrating https://github.com/krzkaczor/TypeChain to use ts-generator. When it's done, its API should be more stable. I see that in your case finding source files to transpile is more complicating then just specifing glob pattern but I would be more than happy to tweak ts-generator API to match this use case.

What do you think?

Support discriminated unions

type X = { type: 'a', value: number } | { type: 'b', value: string }
function isX(obj: any): obj is X {
  return (
    (obj.type === 'a' && typeof obj.value === 'number') ||
    (obj.type === 'b' && typeof obj.value === 'string')
  )
}

Recursive type guards created by overwriting existing _.guard.ts file only test typeof === "object"

I noticed that the typeguards for these recursive types don't perform a useful test:

index.ts:

// Recursion
/** @see {isRecursiveType} ts-auto-guard:type-guard */
export type RecursiveType = { children: RecursiveType[] };

// Mutual recursion
/** @see {isParentType} ts-auto-guard:type-guard */
export type ParentType = { type: 'parent', children: ChildType[] };

/** @see {isChildType} ts-auto-guard:type-guard */
export type ChildType = { type: 'child', parent: ParentType };

index.guard.ts:

export function isRecursiveType(obj: any, _argumentName?: string): obj is RecursiveType {
    return (
        typeof obj === "object"
    )
}

export function isParentType(obj: any, _argumentName?: string): obj is ParentType {
    return (
        typeof obj === "object"
    )
}

export function isChildType(obj: any, _argumentName?: string): obj is ChildType {
    return (
        typeof obj === "object"
    )
}

github link in npm

It feels safer when there is a link to repository in npm package page :)

Add license file

I see that there’s a license referenced in the package.json, MIT, but this isn’t show in GitHub.

Please add a license file named ‘LICENSE’

Sent from PPHub

Windows support

package.json contains some linux-specific code:

  • chmod in 'build' command
  • bunch of stuff in 'test' command

I am wondering if it could be improved somehow. I made some workarounds, but I am not very happy about them...

Correctly import generated type guards for sub-types

Input

// room.ts

import { House } from "./house"

/** @see {isRoom} ts-auto-guard:type-guard */
interface Room {
  width: number,
  height: number,
}
// house.ts

/** @see {isHouse} ts-auto-guard:type-guard */
interface House {
  address: string,
  rooms: Room[]
}

Output

// house.guard.ts

import { House } from "./house"
import { isRoom } from "./room.guard"

export function isHouse(obj: any): obj is House {
  return (
    typeof obj === "object" &&
    typeof obj.address === "string" &&
    Array.isArray(obj.rooms) &&
    obj.rooms.every(isRoom)
  )
}

Error: Node must be exported

Failing test:

testGuard(
'nested interface with type guard',
`
/** @see {isBar} ts-auto-guard:type-guard */
interface Bar {
bar: number
}
/** @see {isFoo} ts-auto-guard:type-guard */
export interface Foo {
foo: Bar,
}`,
`
import { Foo } from "./test";
export function isFoo(obj: any): obj is Foo {
return (
typeof obj === "object" &&
isBar(obj.foo) as boolean
)
}`,
{ skip: true }
)

Error: Node must be exported:

interface Bar {
    bar: number
}

In this case the node does not need to be imported because it's in the same file, so no complaint is necessary.

Perhaps remove the error and just let the compiler inform the user that their code is broken.

TypeError: realpath is not a function

Using node v12.18.2 or v13.13.0, I'm getting the follow error:

(node:47407) UnhandledPromiseRejectionWarning: TypeError: realpath is not a function
    at visitDirectory (/Users/aneil/code/test-ts-auto-guard/node_modules/typescript/lib/typescript.js:18327:45)
    at Object.matchFiles (/Users/aneil/code/test-ts-auto-guard/node_modules/typescript/lib/typescript.js:18323:13)
...
    at Object.parseJsonConfigFileContent (/Users/aneil/code/test-ts-auto-guard/node_modules/typescript/lib/typescript.js:28544:16)
(node:47407) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

Replicate with a folder containing the following files:

  • tsconfig.json
{
  "compilerOptions": {
    "baseUrl": "./src",
    "outDir": "./lib",

  },
  "include": ["index.ts"],
  "exclude": ["node_modules", "**/__tests__/*"]
}
  • index.ts
/** @see {isMyType} ts-auto-guard:type-guard */
type MyType = string | number;
  • package.json
{
  "name": "test-ts-auto-guard",
  "version": "1.0.0",
  "main": "lib/index.js",
  "types": "lib/index.d.ts",
  "scripts": {
    "build": "tsc"
  },
  "dependencies": {
  },
  "devDependencies": {
    "ts-auto-guard": "^1.0.0-alpha.1"
  }
}

I get the error with:

npm install
node_modules/.bin/ts-auto-guard

Incorrect object check

@keithlayne points out on Gitter:

@rhys-vdw I don’t know if you did this on purpose, but some of your nested objects can error on null values like so in your gist:

> a = null
null
> typeof a === 'object' && typeof a.b === 'string'
TypeError: Cannot read property 'b' of null

Bug: Fails to use existing type guard when type is wrapped in `Readonly`.

e.g.

/** @see {isFoo} ts-auto-guard:type-guard */
interface Foo {
  value: number
}

/** @see {isBar} ts-auto-guard:type-guard */
interface Bar {
  foo: Readonly<Foo>
}
function isFoo(obj: any): obj is Foo {
  return typeof obj === "object" && typeof obj.value === "number"
}

// EXPECTED:
function isBar(obj: any): obj is Bar {
  return typeof obj === "object" && isFoo(obj.foo)
}

// ACTUAL:
function isBar(obj: any): obj is Bar {
  return typeof obj === "object" && typeof obj.foo === "object" && typeof obj.foo.value === "number"
}

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.