Typescript: New error: Property 'value' does not exist on type 'never'

Created on 25 Mar 2020  路  7Comments  路  Source: microsoft/TypeScript

https://github.com/linkedin/css-blocks/blob/6023475e9ab9a01cda6daa71986a9b4932c16ecd/packages/@css-blocks/core/src/BlockTree/Block.ts#L443

packages/@css-blocks/core/src/BlockTree/Block.ts:443:48 - error TS2339: Property 'value' does not exist on type 'never'.

443           let klass = otherBlock.getClass(next.value);
                                                   ~~~~~

packages/@css-blocks/core/src/BlockTree/Block.ts:445:32 - error TS2339: Property 'next' does not exist on type 'never'.

445             let another = next.next();
                                   ~~~~

To repro:
1) yarn
2) tsc -b -f packages

Working as Intended

Most helpful comment

I agree with @RyanCavanaugh that this code block isn't reachable and I think the error is very helpful... I wish I would have had it earlier! I agree with @amcasey that an error telling me that one of the branches of the if statement isn't reachable would be a slightly nicer error, but I think I would have been able to sort out my mistake based on the error as-is.

All 7 comments

This appears to be a correct error. The relevant code looks like this (highlights for emphasis):

    let next = node.next();
    if (isRootNode(node) && next && isAttributeNode(next) && typeof next.namespace === "string") {
//                                  ^^^^^^^^^^^^^^^^^^^^^
      let otherBlock = this.getReferencedBlock(next.namespace);
      if (otherBlock) {
        if (next && isClassNode(next)) {
//                  ^^^^^^^^^^^^^^^^^
          let klass = otherBlock.getClass(next.value);

isAttributeNode returns arg is Attribute where Attribute is { type: "Attribute" }. isClassNode returns arg is ClassName where ClassName is { type: "Class" }. I don't see any other out-of-band assignments to next; I think this code actually does have a bug in it either from a runtime perspective or from an incorrect typings perspective - no value could satisfy both of those conditions.

cc file authors @chriseppstein @ramitha @amiller-gh for commentary

@RyanCavanaugh Is there some way we could make it easier to work backwards from the error to the problem? Maybe the if block could report that its condition is unsatisfiable?

I'll look into this right now.

I agree with @RyanCavanaugh that this code block isn't reachable and I think the error is very helpful... I wish I would have had it earlier! I agree with @amcasey that an error telling me that one of the branches of the if statement isn't reachable would be a slightly nicer error, but I think I would have been able to sort out my mistake based on the error as-is.

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Roam-Cooper picture Roam-Cooper  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

dlaberge picture dlaberge  路  3Comments